Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2008
    Location
    England
    Posts
    285
    Tokens
    0

    Default [PHP] Unique hit counter

    This script runs off the IP address of the user, therefore if they vist the site twice, it will go up once, not twice!

    To start with, we need to be able to find out their IP address.
    PHP Code:
    $ip $_SERVER[REMOTE_ADDR]; 
    We now need a text-file to log the IP addresses. In this guide, I'll be using vists.txt - Remember to set the CHMOD to 777 otherwise the script will not be able to add in the IP addresses.

    Now we need to make the script write 1 IP/line
    PHP Code:
    $already="FALSE";
    if(!
    file_exists("visits.txt"))
    {
       echo 
    "Missing text file!";
    }
    else
    {
    $database=file("visits.txt"); 
    for(
    $i$i<sizeof($database); $i++)
    {
    trim($database[$i]); 
    if(
    $database[$i]!="")
      
    $visitors++; 
    if(
    $database[$i]==$ip)
       
    $already="TRUE"
    }

    Now if $already = flase (Meaning they havn't been on the website before, we can add them to the list
    PHP Code:
    if($already=="FALSE")
    {
    $database=fopen("visits.txt","a");
    fwrite($database,"\n$ip");
    fclose($database);
    visitors++; 
    The full script for the lazy people is
    </span>

    </span>

    </span>
    PHP Code:
    <?php

    $ip 
    $_SERVER[REMOTE_ADDR];

    $already="FALSE"
    if(!
    file_exists("visits.txt")) 
    {
       echo 
    "Missing text file!";
    }
    else
    {
    $database=file("visits.txt"); 
    for(
    $i$i<sizeof($database); $i++)
    {
       
    $database[$i]=trim($database[$i]); 
       if(
    $database[$i]!="")       $visitors++; 
       if(
    $database[$i]==$ip)
          
    $already="TRUE"
    }

    if(
    $already=="FALSE")
    {
       
    $database=fopen("visits.txt","a");
       
    fwrite($database,"\n$ip");
       
    fclose($database);
       
    $visitors++;
    }

    echo 
    "You are $visitors visitor!";

    }

    ?>

  2. #2
    Join Date
    May 2006
    Posts
    1,797
    Tokens
    0

    Latest Awards:

    Default

    Now if $already = flase (Meaning they havn't been on the website before, we can add them to the list

    PHP Code:
    if($already=="FALSE")
    {
    $database=fopen("visits.txt","a");
    fwrite($database,"\n$ip");
    fclose($database);
    visitors++; 
    Havent added $ sign to visitors var in last line
    Coming and going...
    Highers are getting the better of me

  3. #3
    Join Date
    Jan 2008
    Location
    England
    Posts
    285
    Tokens
    0

    Default

    Quote Originally Posted by MrCraig View Post
    Havent added $ sign to visitors var in last line
    Whoops! Thanks for pointing that out!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •