Hi to all,
I need to know how to use the cookie in php,my problem is that when i clicked the log-out.and then i will go to my browser and click the back button.it will go back to the user where it is still logging in.but what i want is that, when i click the back button of the browser it will go to my log in page and it will asked to input username and password.can you help me on this i am
still learning on this.Thank you in advance.
here is my code
log-in.php
<?php
include_once ('condb.php');
$expire_time = time() + 60;
setcookie("name",$expire_time);
if (ISSET($_POST['login']))
{
$txtusername = $_POST['txtusername'];
$txtpassword = $_POST['txtpassword'];
$sql = "SELECT name,password from cookie_tbl where name = '$txtusername' and
password = '$txtpassword'";
$result= mysql_query($sql);
if(mysql_num_rows($result)>0)
header('location:userlogin.php');
else
echo "invalid username and password";
mysql_close();
}
?>
<html>
<title>login</title>
<body>
<h1>log-in page</h1>
<form method = "post">
<table border="2">
<tr>
<td>Name:</td>
<td><input type="text" name ="txtusername"></input></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="text" name="txtpassword"></input></td>
</tr>
<tr >
<td></td>
<td>
<input type="submit" name="login" value="login"></input>
<input type="reset" value="cancel"></input>
</td>
</tr>
</form>
</body>
</html>
userlogin.php
<html>
<h1>user login</h1>
<form action ="userlog-out.php" method ="post" >
<div style = "color:red;">
<?php echo 'Welcome' . $_COOKIE ["name"]; ?>
</div>
<input type="submit" name="logout" value ="log out">
</form>
</html>
userlog-out.php
<?php
$expire_time = time() - 60;
setcookie("name",$expire_time);
?>
<html>
<title>log-out</title>
<body>
<h1>user log-out</h1>
<h2>YOu have successfully log-out.</h2>
<a href="login.php">Click here to Login</a>
</body>
</html>