Skip to content

Instantly share code, notes, and snippets.

@joequery
Created November 4, 2015 09:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joequery/84db198983ebf66c23dc to your computer and use it in GitHub Desktop.
Save joequery/84db198983ebf66c23dc to your computer and use it in GitHub Desktop.
PHP Session Example
<?php
session_start();
$num_visits = $_SESSION['page_load_count'];
if(isset($_GET['reset']) || !isset($num_visits)){
$num_visits = 0;
}
$num_visits++;
$_SESSION['page_load_count'] = $num_visits;
?>
<h1>Hello</h1>
<p>You have visited this page <?= $num_visits ?> times</p>
<p><a href="?reset=true">Reset</a></p>
<?php if($num_visits >= 5): ?>
<h2>Wow!</h2>
<p>You sure come to this page a lot.</p>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment