Created
November 4, 2015 09:07
-
-
Save joequery/84db198983ebf66c23dc to your computer and use it in GitHub Desktop.
PHP Session Example
This file contains 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(); | |
$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