Created
September 11, 2014 15:30
-
-
Save khoand0000/359f136456755cf235f1 to your computer and use it in GitHub Desktop.
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 | |
// set the variable to 0, it'll matter only if the cookie for the variable is not set | |
$visitCounter = 0; | |
// if cookie is set for the variable, it'll go to $visitCounter and get added by 1; otherwise it'll show 0 for tha variable | |
if(isset($_COOKIE['visitCounter'])){ | |
$visitCounter = $_COOKIE['visitCounter']; | |
$visitCounter ++; | |
} | |
// if the last visist cookie is set, it'll pass the value to $lastVisit, and it'll be displayed below; | |
if(isset($_COOKIE['lastVisit'])){ | |
$lastVisit = $_COOKIE['lastVisit']; | |
} | |
// set cookie for visitCounter | |
setcookie('visitCounter', $visitCounter+1, time()+3600); | |
// set cookie for last visit | |
setcookie('lastVisit', date("d-m-Y H:i:s"), time()+3600); | |
// show the respected values | |
// is the variable is not set, say 'welcome', otherwise show the info about visit number and last visit date | |
if($visitCounter == 0){ | |
echo "Welcome"; | |
} else { | |
echo "This is your visit number ".$visitCounter; | |
echo '<br>'; | |
echo "Last time, you were here ".$lastVisit; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment