I'm confused about cookie.
in php settings, there are two configuration options:
session.cache_expire (value 180), session.cookie_lifetime (value 0).
What are differences between them?
I use this code to create a simple login/logout page. But after closing the browser, I'm still logged in (although the session.cookie_lifetime is set to zero). Does the option session.cache_expire (value 180) cause that behaviour.
login.php
<?php
session_start();
?>
<html>
<head>
<title>Login Form</title>
</head>
<body>
<h1>Welcome to homepage !</h1>
<?php
if (!isset($_SESSION['valid_user']))
{
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
if (empty($username) || empty($password))
echo 'Please enter your username and password.<br>';
else
{
// neu da danh username va password thi se check voi csdl
$db = new mysqli('localhost', 'tiger', '123456', 'auth');
if (mysqli_connect_errno())
{
echo 'Could not connect to database.<br>';
exit();
}
$query = 'select name from authorized_users where name = \''.$username.'\''.
' and password = sha1(\''.$password.'\')';
$result = $db->query($query);
if ($result->num_rows > 0)
$_SESSION['valid_user'] = $username;
else
echo 'You have provided wrong username and password.<br>';
if ($result) $result->free();
$db->close();
}
}
// neu da log in roi
if (isset($_SESSION['valid_user']))
{
echo '<p>You have logged in as <strong>'.$_SESSION['valid_user'].'</strong><br>';
echo '<p>Click <a href=\'logout.php\'>here</a> to logout.<br>';
}
else
{
?>
<form action="login.php" method="POST">
<table border="0">
<tr>
<td>Username: </td>
<td><input type="text" name="username" size="30" maxlength="30"></td>
</tr>
<tr>
<td>Password: </td>
<td><input type="password" name="password" size="30" maxlength="30"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Log In"></td>
</tr>
</table>
</form>
<?php
}
?>
</body>
</html>
logout.php
<?php
session_start();
?>
<html>
<head>
<title>Logout</title>
</head>
<body>
<h1>Logout page !</h1>
<?php
if (isset($_SESSION['valid_user']))
{
unset($_SESSION['valid_user']);
session_destroy();
echo 'You have logged out successfully.<br>';
}
else
echo 'You have not logged in yet, so you can\'t logout. Sorry.<br>';
?>
<p>Click <a href="login.php">here</a> to back to login page</p>
</body>
</html>
thank u