Created
September 6, 2013 03:55
-
-
Save lionhylra/6459340 to your computer and use it in GitHub Desktop.
session and cookie control in php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
//store a session variable | |
if (isset($_SESSION['pageviews'])) { | |
$_SESSION['pageviews']++; | |
} | |
else { | |
$_SESSION['pageviews'] = 1; | |
} | |
?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
<?xml version="1.0" encoding="UTF-8"?> | |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
<body> | |
<?php | |
echo "Pageviews=". $_SESSION['pageviews'] . "<br/>"; | |
?> | |
<p>Re-load page to increment counter.</p> | |
<p>Or, <a href="session3.php">destroy</a> the session by calling <tt>session3.php</tt></p> | |
</body> | |
</html> | |
=================== | |
<?php | |
session_start(); // need to call this first to restore access to session variables | |
session_destroy(); // now can destroy them | |
header("location:session2.php"); // re-direct to session2.php | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment