User Log-out

Finally, the last thing we need is a log out script. Just put a link called Log Out anywhere in the members section which directs the user to this script:

<?php

// expire cookie
setcookie ("loggedin", "", time() - 3600);

echo "You are now logged out.<br>";
echo "<a href=\"login.html\">Log in</a>.";

?>

This script just removes the cookie which said they were logged in. And that's it! If you have trouble putting all the code together, you can take a look at the whole thing here.