ICS 325
Lab 18
Working With Sessions
(Linux Redhat 7.1)
Log onto
redhat.ics.metrostate.edu using your loginid and password given in class.
$ cd
$ cd public_html
$ mkdir lab18
$ cd lab18
<?php
session_start();
if(isset($submit)){
if
(($uname == "METRO") && ($pword == "STATE")){
$loggedIn
= "IN";
session_register("loggedIn");
echo
"Welcome to my site your Session has been set<br />";
echo
"You can now click on the link below<br />";
}
}
?>
<html>
<head>
<title>Lab
18 Sessions</title>
</head>
<body>
<form
action="<? PHP_SELF ?>" method="post"
name="myForm">
User
Name: <input type="text" name="uname" /><br />
Password: <input type="text"
name="pword" /><br />
<input
type="submit" value="Submit" name="submit" />
</form>
<a href="locked.php">Click Here</a>
</body>
</html>
<?php
session_start();
if ($loggedIn ==
"IN"){
echo "Your Session ID = " . session_id();
} else{
header(
"location:http://redhat.ics.metrostate.edu/~su04325??/lab18");
}
?>
Invoke the script using the
following link,
http://redhat.ics.metrostate.edu/~su04325??/lab18/
<?php
session_start();
session_destroy();
?>
Invoke the script using the
following link,
http://redhat.ics.metrostate.edu/~su04325??/lab18/killSession.php
Re-invoke the previous script using
the following link,
http://redhat.ics.metrostate.edu/~su04325??/lab18/
Notice the change
Reminder: If your
page appears to have expired, you may need to add
header
(“Cache-control: private”);
after the function call to session_start()