Metropolitan State University

ICS 325

Building Services on the Internet

 

Lab 20

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 lab20

$ cd lab20

 

 

  1.  Edit the following file with the name as “index.php” using pico:

 

<?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 20 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>

 

 

  1.  Edit the following file with the name as “locked.php” using pico:

 

<?php

session_start();

if ($loggedIn == "IN"){

   echo "Your Session ID = " . session_id();

}  else{

      header(

      "location:http://redhat.ics.metrostate.edu/~f04325??/lab20"); }

?>   

 

Invoke the script using the following link,

http://redhat.ics.metrostate.edu/~f04325??/lab20/     

 

 

  1. Edit the following file with the name as “killSession.php” using pico:

 

<?php

session_start();

session_destroy();

?>

  

 

Invoke the script using the following link,

http://redhat.ics.metrostate.edu/~f04325??/lab20/killSession.php

 

Re-invoke the previous script using the following link,

http://redhat.ics.metrostate.edu/~f04325??/lab20/     

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()