Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts

    Any effective hit counter without cookie?

    Hi friends,

    I want to setup a website hit counter to record the hits of users.

    My intention is to..
    1) Get the IP address of client.
    2) Check whether it is a continuation of his previous visit.
    3) If there is a considerable delay b/w his previous hit, increment counter; else make delay to NULL

    These steps are to be carried out in all pages.

    Everything is OK, except in Step 1 . It fails in the case of a set of users who share a common IP to connect to Internet. ie. If some of them are simultaneously visiting the site, then I can't keep the delay value as expected.

    Any other idea?
    (Worked around $_SERVER['HTTP_X_FORWARDED_FOR'], but no o/p for that line.)

    Thanks n regards,
    art
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #2
    Regular Coder mic2100's Avatar
    Join Date
    Feb 2006
    Location
    Scunthorpe
    Posts
    562
    Thanks
    15
    Thanked 28 Times in 27 Posts
    hi,

    one question...

    y no cookies???

    This would be so much easier using cookies!!!

    Thanks

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    I feel it's not good to export something to visitor's system(I may be a wrong..).
    However if no other way, I'll compromise .

    BW What's the exact purpose of HTTP_X_FORWARDED_FOR? Is it useful anyway?

    Thanks,
    art.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #4
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Quote Originally Posted by abduraooft View Post
    I feel it's not good to export something to visitor's system(I may be a wrong..).
    However if no other way, I'll compromise .

    BW What's the exact purpose of HTTP_X_FORWARDED_FOR? Is it useful anyway?

    Thanks,
    art.
    it returns the users IP address but apparantly it can be easily faked.

  • #5
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,146
    Thanks
    2
    Thanked 333 Times in 325 Posts
    HTTP_X_FORWARDED_FOR is an optional header that is provided by non-anonymous proxy servers that indicates the IP address they received the request from (this can be an array of IP addresses if the request was handled by a string of proxies.) Anonymous proxy servers (those that don't want you to know they are proxies) either don't send this header or set it to their own IP address to make you think the request came from them. An anonymous proxy could also set it to a different value on each request, even if those requests all came from the same IP, to make you think each request is from a different address.

    If HTTP_X_FORWARDED_FOR is present, you can use it to help distinguish between different requests made through one proxy server (same REMOTE_ADDR) but you cannot really rely on it for any mission critical application (which is true of all the HTTP_ headers, they are all optional and they can all be faked.)
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #6
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Quote Originally Posted by CFMaBiSmAd View Post
    HTTP_X_FORWARDED_FOR is an optional header that is provided by non-anonymous proxy servers that indicates the IP address they received the request from (this can be an array of IP addresses if the request was handled by a string of proxies.) Anonymous proxy servers (those that don't want you to know they are proxies) either don't send this header or set it to their own IP address to make you think the request came from them. An anonymous proxy could also set it to a different value on each request, even if those requests all came from the same IP, to make you think each request is from a different address.

    If HTTP_X_FORWARDED_FOR is present, you can use it to help distinguish between different requests made through one proxy server (same REMOTE_ADDR) but you cannot really rely on it for any mission critical application (which is true of all the HTTP_ headers, they are all optional and they can all be faked.)
    meh its a little more detailled than mine but couldnt find out much about it on the php website (mayb ei should look harder next time)

  • #7
    Regular Coder croatiankid's Avatar
    Join Date
    Jan 2006
    Posts
    665
    Thanks
    1
    Thanked 12 Times in 12 Posts
    Well, in your about/terms of use/whatever page, you can mention that they've got a cookie from you for statistical analysis or whatever.

  • #8
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    You can get easily get hit of this link

    <a href="mysite/mypage.html">MyPage</a>

    Does any one of you know how to get this hit

    <a href="?mysit=mypage.html">MyPage</a>

    If anyone gives me a hint, or complete solution, i'll post flat file Hit's script, which i use only for visitors script...

  • #9
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Quote Originally Posted by rafiki View Post
    it returns the users IP address but apparantly it can be easily faked.
    Thanks, but I get nothing when I used
    PHP Code:
    echo $_SERVER['HTTP_X_FORWARDED_FOR']; 
    regards,
    art
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #10
    Regular Coder mic2100's Avatar
    Join Date
    Feb 2006
    Location
    Scunthorpe
    Posts
    562
    Thanks
    15
    Thanked 28 Times in 27 Posts
    hi matak,

    you can use the following php code at the top of the page to navigate to the link...

    PHP Code:
    <?

    if(isset($_GET['mysit'])):

    //in here you can access the page selected by checking the variable $_GET['mysit']
    //if you then want to log this, make your db connection here.

    /*

    other processing code here

    */

    //please make sure that this HEADER is at the bottom of whatever code you place in this if statement
    header('Location: '.$_GET['mysit']);

    endif;

    ?>
    now if you have some code for an hit counter i would also really like it.

    Thanks...

    Mic
    Last edited by mic2100; 08-08-2007 at 10:08 AM. Reason: various changes

  • #11
    Banned
    Join Date
    Apr 2007
    Posts
    428
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Feel free to comment on this visitors script..

    PHP Code:
    function getVisits($variable) {

        
    $visits = array();
        
        
    $date date('Y-m-d');
        
        if (
    $handle opendir('base/stats/')) {
        while (
    false !== ($file readdir($handle))) {
            if (
    $file != "." && $file != "..") {
               
    array_push($visits$file);
            }
        }
        
    closedir($handle);
        }
        
    $key array_search($date.$variable$visits);
        
        if (
    $key !== FALSE) {
            
            echo 
    "Visits: ".count($visits);
            
        }
        elseif (
    $key === FALSE){
            
    $file fopen("baza/stats/".$date.$variable'a');
            
    fwrite($file$variable);
            
    fclose($file);
        
            
    getVisits($variable);
        }

    Anway this script writes IP adresses and dates in file, so that tomorow you can still get visits from same IP's

  • #12
    Regular Coder mic2100's Avatar
    Join Date
    Feb 2006
    Location
    Scunthorpe
    Posts
    562
    Thanks
    15
    Thanked 28 Times in 27 Posts
    thanks,
    but still no one as really answered the original post, is there a way to log user visits without using a cookie? I didn't ask this n i think using them is ok since that most users are now beyond to point of paranoia about them.

  • #13
    Regular Coder meth's Avatar
    Join Date
    Jan 2003
    Posts
    262
    Thanks
    0
    Thanked 9 Times in 9 Posts
    If by user, you're referring to a particular user logged on to a particular computer and if you are implying a solution along as simple lines as a cookie, then no, there isn't.

    Perhaps you may want to check out a few php tracking systems:

    phpOpenTracker and phpSniff
    I do Web Design, Brisbane based.
    More time spent in PHP/MySQL Web Development.
    And Search Engine Optimisation takes up the rest of it.

  • #14
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Quote Originally Posted by meth View Post
    If by user, you're referring to a particular user logged on to a particular computer and if you are implying a solution along as simple lines as a cookie, then no, there isn't.
    Well, I don't think cookie is so effective. What happens when someone block/clear cookie from his system?

    Anyway, if I'm going to use cookie, I assume the following steps will work

    1) Check for the value (accessed time in seconds).
    2) Check DB with this value and the current IP
    3) If a considerable delay, increment count.
    4) Set a new cookie.

    please correct me if anything wrong (I haven't used a cookie yet)

    thanks
    art
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #15
    New Coder
    Join Date
    Aug 2007
    Location
    Wagga, Australia
    Posts
    59
    Thanks
    0
    Thanked 1 Time in 1 Post
    you could simply store a persons ip address and the date they last were on
    and then say

    PHP Code:
    $date date("Ynj");
    $query mysql_query("SELECT date, count FROM counter WHERE ip = {$_SERVER["REMOTE_ADDR"]}");

    $last_visit mysql_fetch_array($query);

    if(empty(
    $last_visit["date"])) {
      
    mysql_query("INSERT INTO counter (ip, date, count) VALUES ('{$_SERVER["REMOTE_ADDR"]}', '$date', '1')");
    }
    else if(
    $last_visit["date"] <= $date 10) {
      
    $count $last_visit["count"] + 1;
      
    mysql_query("UPDATE counter SET date = '$date' AND count = '$count' WHERE ip = {$_SERVER["REMOTE_ADDR"]}");



  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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