How to maintain state in a stateless web Shirley Cohen

How to maintain state
in a stateless web
Shirley Cohen
What is meant by state?
To maintain state means the ability to retain
values of variables and to keep track of
users who are logged into the system.
Methods for maintaining state
• Cookies
• Sessions
• Passing [hidden] variables
What is a cookie?
Cookies are simple text strings of the form
of name=value which are stored
persistently on the client’s machine.
A URL is stored with each cookie and it is
used by the browser to determine whether
it should send the cookie to the web
Cookie Example
setCookie(“count”, $count);
Welcome! You’ve seen this site
<?php print($count . ($count == 1 ? “ time!” : “ times!”)); ?>
Common Pitfalls
• Can’t call setCookie() after output has
been sent to the browser
• Can’t have more than 20 cookies/server
• Cookies ONLY persist until the browser
closes UNLESS you specify an expiry
set Cookie(“name”, $value, time() + 3600);
Sessions are just like cookies, except they
store the user’s data on the web server.
Every request has a unique session id.
Sessions are said to be 30% more reliable
than cookies.
Session Example
// start the session
print "<strong>Step 2 - Register Session </strong><br />";
// Get the user's input from the form
$name = $_POST['name'];
// Register session key with the value
$_SESSION['name'] = $name;
// Display the session information:
Welcome to my website <strong><? print $_SESSION['name']; ?></strong>!<br />
Let's see what happens on the <a href="page3.php">next page.</a><br /><br />
Destroying a Session
// start the session
$_SESSION = array();
print "<strong>Step 5 - Destroy This Session </strong><br />";
print "The session is still active";
echo "Ok, the session is no longer active! <br />";
Session Tutorial Site
Passing Variables
<form method="POST" action="main.php">
<input type="hidden" name=“course" value=“print $course">
<input type="hidden" name="student_id" value=“print $student_id">
EID Topic
EID module authenticates a user using a
valid EID and password which are sent to
the UT directory server using SSL. The UT
directory server returns a cookie to the
requestor and the requestor can then
retrieve the relevant information about the
Web Central Users
Use an .htaccess file on the directory they want to protect:
.htaccess file to allow access for any valid UT EID
AuthType Anything
AuthName Anything
EID_Required on
require valid-eid
.htaccess file to allow restricted access for a small group
AuthType Anything
AuthName Anything
EID_Required on
require eid UniqueID1 UniqueID2
Web Central EID Tutorial
Non-Web Central Users
• PHP EID Module: David Cook
(not stable at the moment)
• ColdFusion EID Module: Lisa Barden
(now stable according to Eng.)
• Request ITS authorization from:
James M Ferrero
• ???