Professional Documents
Culture Documents
Cookie
Cookie
Index.php
<?php
$action=0;
extract($_REQUEST);
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<fieldset>
</form>
</table>
</fieldset>
</body>
</html>
Index_ctl.php
<?php
extract($_REQUEST);
if($uname=="admin" && $pass=="123"){
setcookie("mycookie", $pass, time() + 300,"/"); // 86400 = 1 day
header("location:home.php");
exit;
}else{
header("location:index.php?action=1");
exit;
}
?>
home.php
<?php
if(!($_COOKIE['mycookie']>0)) {
header("location:index.php");
exit;
}
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
Welcome <?php print($_COOKIE['mycookie']);?><br>
<a href="logout.php">logout</a>
</body>
</html>
logout.php
<?php
unset($_COOKIE['mycookie']);
setcookie('mycookie', null, -1,"/"); // 86400 = 1 day
header("location:index.php");
exit;
?>