Hello,
I have added something to my login script to keep the users logged in if they check the box, here is what i have added -
if(isset($_POST['saveme'])) {
//Keep logged in
session_set_cookie_params(60480000, '/', '');
}
And here is the entire script -
<?php
require_once("db/connect.php");
session_start();
//Field Data
if (isset($_POST['Submit'])){
$username = (isset($_POST['username'])) ? $_POST['username'] : '';
$password = (isset($_POST['password'])) ? $_POST['password'] : '';
$submitted = $_POST['Submit'];
if ( empty($username) )
{
$error['username'] = "Please enter your username";
} if ( empty($password) )
{
$error['password'] = "Please enter your password";
}
else if ($username && $password){
//////////////////////////////////////////////////
$query = sprintf("SELECT * FROM users WHERE username='%s' AND password='%s'",$username,md5($password));
$result = mysql_query($query);
$rowAccount = mysql_fetch_array($result);
//////////////////////////////////////////////////
if(isset($_POST['saveme'])) {
//Keep logged in
session_set_cookie_params(60480000, '/', '');
}
if ($rowAccount){
$_SESSION['id'] = $rowAccount['username'];
header("Location:user_area/");
exit;
}else{
$error['checklogin'] = "Wrong username or password";
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link rel="stylesheet" href="main.css" type="text/css" />
<link rel="stylesheet" href="style.css" type="text/css" />
</head>
<body>
<div id="wrapper">
<div id="log-content">
<?php
// If error found
if ( isset($error) ) {
// Loop errors
foreach($error AS $e) {
echo "<div id='error'><ul><li>" . $e . "</li></ul></div>";
}
}
?>
<div id="login">
<form id="form1" name="form1" method="post" action="index.php">
<div id="field"><label id="login-label">Username</label><br /><input type="text" id="input" name="username" size="34" value="<?php echo (isset($_POST['username'])) ? $_POST['username'] : ''; ?>" /></div>
<div id="field" style="margin-top:20px;"><label id="login-label">Password</label><br /><input type="password" id="input" name="password" size="34" /></div>
<div id="field"><input type="checkbox" name="saveme" value=""><label>Keep me logged in</label></div>
<input type="hidden" id="submitted" name="submitted" />
<input type="submit" id="Submit" name="Submit" />
</form>
</div>
</div>
</div>
</body>
</html>
Now have i placed it in the wrong place because when i login and then close the page then reopen it i have to relogin so anyone know how i could fix this?