Derek Bridge

Department of Computer Science,
University College Cork



State management

Ways to achieve state management

Cookies for state management

Cookies example

Persistent cookies and in-memory cookies

Cookies in PHP: sending them

Cookies in PHP: sending them

(*unless PHP's output buffering is enabled, which it is not in our intallation)

Cookies in PHP: accessing them

counter.php: simple example

Counting the number of times a page has been accessed by a client

 if (! isset($_COOKIE['numvisits'])) 
    $counter = 1;
    $counter = $_COOKIE['numvisits'] + 1;
 setcookie("numvisits", $counter, time()+86400*365*5);
 echo "

Welcome! (Visit number: {$counter})

"; ?>

Some of the issues with cookies