Skip to content

Instantly share code, notes, and snippets.

@lionhylra
Created September 6, 2013 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lionhylra/6459340 to your computer and use it in GitHub Desktop.
Save lionhylra/6459340 to your computer and use it in GitHub Desktop.
session and cookie control in php
<?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