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 7 of 7
  1. #1
    Join Date
    Jun 2005
    Location
    Manchester
    Posts
    3,187
    Tokens
    0

    Latest Awards:

    Default | PHP Stats - Tutorial |

    Hey guys.

    Heres my 4th PHP tutorial just rate it and tell me what you think.

    We'll be going over user information and statistics.

    We'll be going through loads.

    Users IP.

    Too show the users IP adress

    PHP Code:
    <?php echo $_SERVER["REMOTE_ADDR"]; ?>
    Very simple, one line of code just place it in your table or wherever you want the IP adress to show.

    An advanced and better way of getting someones IP adress

    PHP Code:
    <?php 

    if(getenv(HTTP_CLIENT_IP)) { 
              
    $host getenv(HTTP_CLIENT_IP); 

    elseif(
    getenv(HTTP_X_FORWARDED_FOR)) { 
              
    $host getenv(HTTP_X_FORWARDED_FOR); 

    else { 
              
    $host $REMOTE_ADDR


    ?>
    Browser Info

    This is another easy one line code.

    PHP Code:
    <?php echo $_SERVER["HTTP_USER_AGENT"]; ?>
    Very basic and easy too use.

    Referer

    Heres how too see what site they came from.

    PHP Code:
    <?php echo $_SERVER["HTTP_REFERER"]; ?>
    Hit Counter

    Now there a lot of different hit counters out there.

    We're going to be using one like i'm using on my site, one thats run off a text file.

    Now lets create a blank .txt file called count.txt

    Now heres the simple PHP code.


    PHP Code:
    <?php 
     
    $fp 
    fopen("count.txt","r"); 

    $count fread ($fpfilesize 
    ("count.txt")); 

    fclose($fp); 

    $count++; 

    $fp fopen("count.txt","w"); 

    fwrite($fp$count); 

    fclose($fp); 

    echo 
    "Hits : $count"
    ?>
    Now you need to CHMOD the text file too 777 if you don't know how to do that then you shouldn't use this tutorial.

    This is my 4th tutorial and they will all be used on my upcoming site opening 1st January 2006

    - Dan

  2. #2
    Join Date
    Nov 2005
    Posts
    807
    Tokens
    1,335

    Latest Awards:

    Default

    Cool but as far as i know the more advanced ip should be =
    PHP Code:
     <?php

    if(getenv(HTTP_CLIENT_IP)) {
              
    $host getenv(HTTP_CLIENT_IP);
    }
    elseif(
    getenv(HTTP_X_FORWARDED_FOR)) {
              
    $host getenv(HTTP_X_FORWARDED_FOR);
    }
    else {
              
    $host $_SERVER['REMOTE_ADDR'];
    }

    ?>
    since in the new version of php $_SERVER['REMOTE_ADDR']; replaces $REMOTE_ADDR ...

  3. #3
    Join Date
    Oct 2005
    Location
    In A Town
    Posts
    494
    Tokens
    0

    Default

    this will help alot of the newbies who keep asking about these codes! Well done.
    +rep

  4. #4
    Join Date
    Jul 2004
    Location
    Sunshine Coast, Queensland, AU
    Posts
    1,830
    Tokens
    467

    Latest Awards:

    Default

    i've been tryign to do that for ages

  5. #5
    Join Date
    Jun 2005
    Location
    Manchester
    Posts
    3,187
    Tokens
    0

    Latest Awards:

    Default

    Cheers charlie.

    I may not be up and advanced on the new PHP :p

    Just no that one worked for me in the past.

    - Dan

  6. #6
    Join Date
    Nov 2005
    Posts
    807
    Tokens
    1,335

    Latest Awards:

    Default

    Depends if your host has installed the latest php version or not..

  7. #7
    Join Date
    Dec 2005
    Posts
    16
    Tokens
    0

    Default

    Coooool

Posting Permissions

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