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
    Nov 2008
    Location
    Australia
    Posts
    21
    Tokens
    0

    Default [TUT] Super Simple Page Hits Counter

    Hey!
    This is just to show some newbies to coding how to make a Hits Counter.

    1. Create a File called hits.dat
    2. Copy this code and read the comments to understand it!

    PHP Code:
     
    <? 
    //See's if you made hits.dat! 
    if(file_exists("hits.dat")) 

    //This part shows that you did! 
    $exist_file fopen("hits.dat""r"); 
    $new_count fgets($exist_file255); 
    //Adds a New Hit  
    $new_count++; 
    //closes the file 
    fclose($exist_file); 
    //shows the new hit count 
    print("$new_count"); 
    $exist_count fopen("hits.dat""w"); 
    fputs($exist_count$new_count); 
    fclose($exist_count); 

    else 

    //You Didnt Make a Hits.dat File!  
    echo("Please make a File named Hits.dat!");
    ?>
    It Doesnt Detect by IP or anything. JUst shows how many times the Page has been viewed.

    Pretty Bad Ey!

  2. #2
    Join Date
    Jan 2008
    Posts
    3,711
    Tokens
    100

    Latest Awards:

    Default

    I am not good at all with PHP, so I dont know if this is a good code or not, but nice of you releasing it!
    Let`s wait and see what PHP coders say ^+^

  3. #3
    Join Date
    May 2005
    Location
    San Francisco, CA
    Posts
    7,160
    Tokens
    2,331

    Latest Awards:

    Default

    Just a few changes I'd make...

    PHP Code:
    <?php

    // Check if the file exists or if we can write to the folder..
    if( file_exists'hits.dat' ) || is_writeable'./' ) )
    {
        
        
    // Open the file or if it doesn't exist, make it..
        
    $exist_file fopen'hits.dat''a+' ); 
        
        while( !
    feof$exist_file ) )
        {
        
            
    // Store the contents of the file in the variable $new_count..
            
    $new_count fgets$exist_file500 );
        
        }

        
    // Close the file handle...
        
    fclose$exist_file );

        
    // Check if the variable $new_count has a value, if not, make it '0'    
        
    $new_count = ( $new_count ) ? $new_count '0';
            
        
    //Adds a New Hit  
        
    $new_count++;

        
    // Echo the hit(s)..
        
    echo $new_count;

        
    // Make a new handle for the file, this time we truncate the file to 0 length so we can add the new hits..
        
    $exist_file fopen'hits.dat''w+' );

        
    // Write the new amount of hits to the file..
        
    fwrite$exist_file$new_count );

        
    // Finally, we close the handle to the file to save memory space and to avoid corruption of the file..
        
    fclose$exist_file ); 

    }
    else
    {

        
    // Alert the user..
        
    echo 'Please make the file hits.dat';

    }

    ?>
    Last edited by Invent; 13-11-2008 at 11:07 AM.

  4. #4
    Join Date
    Jul 2008
    Location
    Hastings, UK.
    Posts
    2,050
    Tokens
    0

    Latest Awards:

    Default

    Nice too see that you're releasing it for free, a tip; don't use short tags

  5. #5
    Join Date
    Sep 2006
    Location
    Evanston, Illinois.
    Posts
    2,361
    Tokens
    0

    Latest Awards:

    Default

    I'll implement uniques in a bit, off to school, I'll do in study hall or whatever.
    How could this hapen to meeeeeeeeeeeeeee?lol.

  6. #6
    Join Date
    Nov 2008
    Location
    Australia
    Posts
    21
    Tokens
    0

    Default

    Quote Originally Posted by Invent View Post
    Just a few changes I'd make...

    PHP Code:
    <?php
     
    // Check if the file exists or if we can write to the folder..
    if( file_exists'hits.dat' ) || is_writeable'./' ) )
    {
     
        
    // Open the file or if it doesn't exist, make it..
        
    $exist_file fopen'hits.dat''a+' ); 
     
        while( !
    feof$exist_file ) )
        {
     
            
    // Store the contents of the file in the variable $new_count..
            
    $new_count fgets$exist_file500 );
     
        }
     
        
    // Close the file handle...
        
    fclose$exist_file );
     
        
    // Check if the variable $new_count has a value, if not, make it '0'    
        
    $new_count = ( $new_count ) ? $new_count '0';
     
        
    //Adds a New Hit  
        
    $new_count++;
     
        
    // Echo the hit(s)..
        
    echo $new_count;
     
        
    // Make a new handle for the file, this time we truncate the file to 0 length so we can add the new hits..
        
    $exist_file fopen'hits.dat''w+' );
     
        
    // Write the new amount of hits to the file..
        
    fwrite$exist_file$new_count );
     
        
    // Finally, we close the handle to the file to save memory space and to avoid corruption of the file..
        
    fclose$exist_file ); 
     
    }
    else
    {
     
        
    // Alert the user..
        
    echo 'Please make the file hits.dat';
     
    }
     
    ?>

    That Makes it Better

  7. #7
    Join Date
    Oct 2005
    Location
    Melbourne, Australia
    Posts
    7,554
    Tokens
    0

    Latest Awards:

    Default

    This seems good ! I might use it one day... lol

Posting Permissions

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