Logo
visit counter
Online Now: 1
Snippet Code
if one visits for the first time, it says welcome. otherwise it gives the visit number and says when the user was on the site last time.
<?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;

}



?>
 
Snippet Comments

Add Your Comment

No Comments Yet.

Add Your Comment

 
Snippet Tools
Rate this Snippet:

Rate the difficulty level:

Request Snippet Update


Suggested Difficulty Level: No votes yet.
Current Score: 3.5
Total votes: 2
Total Views: 263

Other top snippets by maque:

1. Read file or site in a string
2. If else
3. Types of loops (for, foreach, while)
4. put links on homepage only
5. Showing date

Search
Search for:







User Panel

User name:

Password:

Register And Post Your Own Snippets

New Snippets

1.  Shorten text and (4 of 1)

2.  file-based simple guest (0 of 0)

3.  adding an entry (0 of 0)

4.  integer to currency (1.33 of 3)

5.  Aggregate IP addresses (0 of 0)

6.  file handling (0 of 0)

7.  testing system with (0 of 0)

8.  Make an php (1 of 1)

9.  allow download in (5 of 1)

10.  redirect in 3 (0 of 0)

11.  live clock with (0 of 0)

12.  visit counter (3.5 of 2)

13.  contact form with (4 of 1)

14.  show a specific (0 of 0)

15.  The & sign (0 of 0)

16.  static variable in (0 of 0)

17.  multiplication table with (0 of 0)

18.  function with multiplicationt (0 of 0)

19.  php generated menu (0 of 0)

20.  drawing a table (0 of 0)

21.  embedded array (one (0 of 0)

22.  checks the week (0 of 0)

23.  put links on (4.5 of 2)

24.  Directory Image Gallery (0 of 0)

25.  TOS (4 of 1)

Home | Forum | Free PHP Web Hosting | Contact | Terms & Conditions |  
Donate
PHPSnips.com - ©2012 Amethyst Creative