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 10 of 10

Thread: Unique hits

  1. #1
    Join Date
    Sep 2006
    Posts
    2,114
    Tokens
    0

    Latest Awards:

    Default Unique hits

    Looking for the code to show unique hits not page hits.

    Thanks +rep for help
    Looking for a good desiner to design a social networking template.

    PM me.

  2. #2
    Join Date
    Aug 2004
    Location
    UK
    Posts
    11,283
    Tokens
    2,031

    Latest Awards:

    Default

    unque hits is harder as it needs to keep track of who its already counted, hence the script has to log vistors and check against the records to know weather to add to the total count. Useuallly this will be refreshed every 24 hours or simlar time fraim and hits will be counted again, so as to save room on the logs.

    Easyest method is use a proper states collecting app, tracewatch for example, although i suppose a script wouldnt be to hard to create for it. Im sure google will probabaly have a few ready to use anyway.

  3. #3
    Join Date
    Sep 2006
    Posts
    2,114
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by 01101101entor View Post
    unque hits is harder as it needs to keep track of who its already counted, hence the script has to log vistors and check against the records to know weather to add to the total count. Useuallly this will be refreshed every 24 hours or simlar time fraim and hits will be counted again, so as to save room on the logs.

    Easyest method is use a proper states collecting app, tracewatch for example, although i suppose a script wouldnt be to hard to create for it. Im sure google will probabaly have a few ready to use anyway.
    Thanks ill have a look for one now.

    +rep
    Looking for a good desiner to design a social networking template.

    PM me.

  4. #4
    Join Date
    Mar 2005
    Location
    Leeds
    Posts
    3,423
    Tokens
    0

    Latest Awards:

    Default

    You can do a number of things to log "unique" views.

    You could set a session/cookie and expire after 24 hours.

    OR

    You can log each IP, if that IP isnt in the log (last 24 hours) it adds it otherwise does nothing. This would be a CPU intensive.

  5. #5

    Default

    google maybe?

  6. #6
    Join Date
    Sep 2006
    Posts
    2,114
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Joltersoft View Post
    google maybe?
    Way to point out the obvious
    Looking for a good desiner to design a social networking template.

    PM me.

  7. #7
    Join Date
    Aug 2006
    Location
    Manchester, UK
    Posts
    2,016
    Tokens
    141
    Habbo
    florx

    Latest Awards:

    Default

    Heres one I found on the interweb

    It uses 2 text files which need to be chmoded to 777 to let it work properly. Alternativly you could use AWstats which show unique hits

    PHP Code:
    <?php

    // #################### Define Important Constants ####################
    // There should be no need to edit these
    define('COUNT_FILE''counter.txt');
    define('IP_FILE''ips.txt');

    // ######################## USER CONFIGURATION ########################
    // Edit the following.. true = yes, false = no

    // Use file locking?
    define('USE_FLOCK'true);

    // Count only unique visitors?
    define('ONLY_UNIQUE'true);

    // Show count as images?
    define('USE_IMAGES'false);

    // Path to the images
    define('IMG_DIR''counter/images/');

    // Image extension
    define('IMG_EXT''.gif');

    // ############################ Functions #############################
    /**
    * We use this function to open, read/write to files.
    *
    * @param  string   Filename
    * @param  string   Mode (r, w, a, etc..)
    * @param  string   If writing to the file, the data to write
    * @return mixed
    */
    function fp($file$mode$data '')
    {
        if (!
    file_exists($file) OR !is_writable($file))
        {
            
    trigger_error("Error: '<code>$file</code>' does not exist or is not writable.");
        }

        if (!(
    $fp = @fopen($file$mode)))
        {
            
    trigger_error("Error: '<code>$file</code>' could not be opened.");
        }

        if (
    USE_FLOCK AND @flock($fpLOCK_EX))
        {
            if (
    $mode == 'r')
            {
                return @
    fread($fpfilesize($file));
            }
            else
            {
                @
    fwrite($fp$data);
            }
            @
    flock($fpLOCK_UN);
        }
        else
        {
            if (
    $mode == 'r')
            {
                return @
    fread($fpfilesize($file));
            }
            @
    fwrite($fp$data);
        }
        @
    fclose($fp);
    }

    /**
    * Get the users ip address.
    * Pulled from my {@link http://www.domainportfolio.us Domain Portfolio} project.
    *
    * @param  none
    * @return string
    */
    function get_ip()
    {
        if (
    $_SERVER['HTTP_X_FORWARDED_FOR'])
        {
            if (
    preg_match_all("#[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}#s"$_SERVER['HTTP_X_FORWARDED_FOR'], $ips))
            {
                while (list(
    $key$val) = @each($ips[0]))
                {
                    if (!
    preg_match("#^(10|172\.16|192\.168)\.#"$val))
                    {
                        
    $ip $val;
                        break;
                    }
                }
            }
        }
        else if (
    $_SERVER['HTTP_CLIENT_IP'])
        {
            
    $ip $_SERVER['HTTP_CLIENT_IP'];
        }
        else if (
    $_SERVER['HTTP_FROM'])
        {
            
    $ip $_SERVER['HTTP_FROM'];
        }
        else
        {
            
    $ip $_SERVER['REMOTE_ADDR'];
        }
        return 
    preg_replace('#([^0-9,\.]+)#'''$ip);
    }

    // ######################## Start Main Script #########################
    // Get current count
    $count fp(COUNT_FILE'r');

    // Do we only want to count 'unique' visitors?
    if (ONLY_UNIQUE)
    {
        
    // Get visitor ip and check against our ip log
        
    $ip get_ip();
        
    $ips trim(fp(IP_FILE'r'));
        
    $ips preg_split("#\n#"$ips, -1PREG_SPLIT_NO_EMPTY);
        
    $visited = (bool)(in_array($ip$ips));

        
    // They've not visited before
        
    if (!$visited)
        {
            
    fp(IP_FILE'a'"$ip\n");
            
    fp(COUNT_FILE'w'$count 1);
        }
        
    // Memory saving
        
    unset($ips);
    }
    else
    {
        
    // No, we wish to count all visitors
        
    fp(COUNT_FILE'w'$count 1USE_FLOCK);
    }

    // Do we want to display the # visitors as graphics?
    if (USE_IMAGES)
    {
        
    $count preg_split("##"$count, -1PREG_SPLIT_NO_EMPTY);
        
    $len count($count);
        
    $display '';

        for (
    $i 0$i $len$i++)
        {
            
    $display .= '<img src="' IMG_DIR $count[$i] . IMG_EXT '" border="0" alt="Simple PHP counter by SecondVersion.com" />&nbsp;';
        }
        echo 
    "<a href=\"http://www.secondversion.com\" style=\"text-decoration: none;\" title=\"Simple PHP counter by SecondVersion.com\">$display</a>";
    }
    else
    {
        
    // Nope, let's just show it as plain text
        
    echo "$count";
    }
    // EoF

    ?>

  8. #8
    Join Date
    Sep 2006
    Posts
    2,114
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by FlorX View Post
    Heres one I found on the interweb

    It uses 2 text files which need to be chmoded to 777 to let it work properly. Alternativly you could use AWstats which show unique hits

    PHP Code:
    <?php

    // #################### Define Important Constants ####################
    // There should be no need to edit these
    define('COUNT_FILE''counter.txt');
    define('IP_FILE''ips.txt');

    // ######################## USER CONFIGURATION ########################
    // Edit the following.. true = yes, false = no

    // Use file locking?
    define('USE_FLOCK'true);

    // Count only unique visitors?
    define('ONLY_UNIQUE'true);

    // Show count as images?
    define('USE_IMAGES'false);

    // Path to the images
    define('IMG_DIR''counter/images/');

    // Image extension
    define('IMG_EXT''.gif');

    // ############################ Functions #############################
    /**
    * We use this function to open, read/write to files.
    *
    * @param  string   Filename
    * @param  string   Mode (r, w, a, etc..)
    * @param  string   If writing to the file, the data to write
    * @return mixed
    */
    function fp($file$mode$data '')
    {
        if (!
    file_exists($file) OR !is_writable($file))
        {
            
    trigger_error("Error: '<code>$file</code>' does not exist or is not writable.");
        }

        if (!(
    $fp = @fopen($file$mode)))
        {
            
    trigger_error("Error: '<code>$file</code>' could not be opened.");
        }

        if (
    USE_FLOCK AND @flock($fpLOCK_EX))
        {
            if (
    $mode == 'r')
            {
                return @
    fread($fpfilesize($file));
            }
            else
            {
                @
    fwrite($fp$data);
            }
            @
    flock($fpLOCK_UN);
        }
        else
        {
            if (
    $mode == 'r')
            {
                return @
    fread($fpfilesize($file));
            }
            @
    fwrite($fp$data);
        }
        @
    fclose($fp);
    }

    /**
    * Get the users ip address.
    * Pulled from my {@link http://www.domainportfolio.us Domain Portfolio} project.
    *
    * @param  none
    * @return string
    */
    function get_ip()
    {
        if (
    $_SERVER['HTTP_X_FORWARDED_FOR'])
        {
            if (
    preg_match_all("#[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}#s"$_SERVER['HTTP_X_FORWARDED_FOR'], $ips))
            {
                while (list(
    $key$val) = @each($ips[0]))
                {
                    if (!
    preg_match("#^(10|172\.16|192\.168)\.#"$val))
                    {
                        
    $ip $val;
                        break;
                    }
                }
            }
        }
        else if (
    $_SERVER['HTTP_CLIENT_IP'])
        {
            
    $ip $_SERVER['HTTP_CLIENT_IP'];
        }
        else if (
    $_SERVER['HTTP_FROM'])
        {
            
    $ip $_SERVER['HTTP_FROM'];
        }
        else
        {
            
    $ip $_SERVER['REMOTE_ADDR'];
        }
        return 
    preg_replace('#([^0-9,\.]+)#'''$ip);
    }

    // ######################## Start Main Script #########################
    // Get current count
    $count fp(COUNT_FILE'r');

    // Do we only want to count 'unique' visitors?
    if (ONLY_UNIQUE)
    {
        
    // Get visitor ip and check against our ip log
        
    $ip get_ip();
        
    $ips trim(fp(IP_FILE'r'));
        
    $ips preg_split("#\n#"$ips, -1PREG_SPLIT_NO_EMPTY);
        
    $visited = (bool)(in_array($ip$ips));

        
    // They've not visited before
        
    if (!$visited)
        {
            
    fp(IP_FILE'a'"$ip\n");
            
    fp(COUNT_FILE'w'$count 1);
        }
        
    // Memory saving
        
    unset($ips);
    }
    else
    {
        
    // No, we wish to count all visitors
        
    fp(COUNT_FILE'w'$count 1USE_FLOCK);
    }

    // Do we want to display the # visitors as graphics?
    if (USE_IMAGES)
    {
        
    $count preg_split("##"$count, -1PREG_SPLIT_NO_EMPTY);
        
    $len count($count);
        
    $display '';

        for (
    $i 0$i $len$i++)
        {
            
    $display .= '<img src="' IMG_DIR $count[$i] . IMG_EXT '" border="0" alt="Simple PHP counter by SecondVersion.com" />&nbsp;';
        }
        echo 
    "<a href=\"http://www.secondversion.com\" style=\"text-decoration: none;\" title=\"Simple PHP counter by SecondVersion.com\">$display</a>";
    }
    else
    {
        
    // Nope, let's just show it as plain text
        
    echo "$count";
    }
    // EoF

    ?>
    Tyvm +rep
    Looking for a good desiner to design a social networking template.

    PM me.

  9. #9
    Foobar Guest

    Default

    Quote Originally Posted by Randomer View Post
    Way to point out the obvious
    If it was so obvious why didn't you use it?

  10. #10
    Join Date
    Sep 2006
    Posts
    2,114
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Retro View Post
    If it was so obvious why didn't you use it?
    I did ;l
    Looking for a good desiner to design a social networking template.

    PM me.

Posting Permissions

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