I am building a website in PHP but I am unsure how I should handle the 'Remember me' option that users have during the login process.
I am unsure whether the save the username and password in JavaScript storage and automatically fill it whenever the user is prompted with the login process again (I doubt this option as it would be very insecure) or somehow make the PHP session never expire (is this even possible?).
Here is the current login script:
<?php
include_once("connection.php");
session_start();
if (!empty($_POST)) {
$sth = $dbh->prepare("SELECT customer_number FROM customers WHERE username = :username AND password = :password");
$sth->bindValue(':username', $_POST['username'], PDO::PARAM_STR);
$sth->bindValue(':password', $_POST['password'], PDO::PARAM_STR);
$sth->execute();
$result = $sth->fetchAll();
if (!empty($result)) {
$_SESSION['customer_number'] = $result[0]['0'];
header("Location: /");
}
else {
header("Location: /");
}
}
?>
The 'Remember me' option is accessible via $_POST['remember']
.
Try below code: