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.
Results 1 to 15 of 15
  1. #1
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Getting vistors from the previous day.

    How can I get the number of visitors per day and then write "$NUMBER visitors yesterday"?

    Thanks
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You mean from Apaches logfile?
    De gustibus non est disputandum.

  • #3
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I don't really know. I just want to get the number of visitors from the day and then on the next day right "There were $number visitors yesterday"
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #4
    New Coder
    Join Date
    Oct 2003
    Location
    AZ
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you gunna use a database of some sort or do you want it to magicaly apear on its own?
    PHP | FreeBSD | MySQL |
    Check documentation... check documentation again and actually read it..do it... doesn't work ask.

  • #5
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    No reason to be a smart alec about it.
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #6
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here's a quick hack that stores a count of visitors for each day as a serialized array in a file and reads from it the number for yesterdays visits:

    PHP Code:
    session_start();

    function 
    logVisit() {
        
    //    check whether the visitor has been tracked
        
    if (isset($_SESSION['visited'])) {
            return 
    false;
        }

        
    $filename 'visits.log';
        
    $visits = array();
        
    $today date('m/d/Y');
        
        
    //    first open the file and get the array...
        
    $content implode(''file($filename));    
        if (
    strlen($content) > 0) {
            
    $visits unserialize($content);        
        } 
        
        
    //    check if a key for today exists, increment that value
        
    if (isset($visits[$today])) {
            
    $visits[$today] += 1;
        } else {
            
    $visits[$today] = 1;    
        }
        
        
    //    store the array in the logfile again    
        
    $fp fopen($filename'w');
        
    fwrite($fpserialize($visits));
        
    fclose($fp);
        
        
    //    mark visitor as tracked by putting a flag into the session    
        
    $_SESSION['visited'] = true;
        return 
    true;
    }

    function 
    getVisitorCount($timestamp) {
        
    $filename 'visits.log';
        
    $visits = array();
        
        
    //    open the file, get the array
        
    $content implode(''file($filename));    
        if (
    strlen($content) > 0) {
            
    $visits unserialize($content);        
        } 
        
        
    //    build date-key
        
    $day date('m/d/Y'$timestamp);
        
        
    //    return the number of visitors for a day
        
    return isset($visits[$day]) ? ($visits[$day]) : (0);
    }

    logVisit();

    $number getVisitorCount(strtotime('yesterday'));
    print 
    "There were $number visitors yesterday"
    Of course you need to include the session part and logVisit() on any page that could/should be reached of the visitor. And after a year or so the logfile might have swelled to 20kB so you might truncated it a little. Set the file permissions for visits.log as it fits your server environment.
    De gustibus non est disputandum.

  • #7
    New Coder
    Join Date
    Oct 2003
    Location
    AZ
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Wasn't supposed to be taken as offensive .

    but anyway. do you want this for a personal log?

    You can like the above store them in a file or you can use a database and use sessions so you can actual visists rather then hits.
    Last edited by coffeedemon; 10-28-2003 at 12:07 AM.
    PHP | FreeBSD | MySQL |
    Check documentation... check documentation again and actually read it..do it... doesn't work ask.

  • #8
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So, mordred, I just need to create visits.log and include it in my index.php page?

    Is that all I need to do?

    Thanks
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #9
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You need to create visits.log in the same directory as index.php, make visits.log writable, and put the PHP code above into your index.php. That's all.
    De gustibus non est disputandum.

  • #10
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    All is well mordred except for this --

    Warning: Cannot send session cookie - headers already sent by (output started at /usr/local/psa/home/vhosts/net-riches.com/httpdocs/includes/index.php:9) in /usr/local/psa/home/vhosts/net-riches.com/httpdocs/includes/visits.php on line 2

    Warning: Cannot send session cache limiter - headers already sent (output started at /usr/local/psa/home/vhosts/net-riches.com/httpdocs/includes/index.php:9) in /usr/local/psa/home/vhosts/net-riches.com/httpdocs/includes/visits.php on line 2


    Know why?
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #11
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can't have HTML output before the session is started. Move session_start() up in your file that it appears before any HTML (or even a single line break!).
    De gustibus non est disputandum.

  • #12
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yay! No more errors! Is it supposed to say "There were 0 visitors yesterday?"

    Thanks
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #13
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    What did you expect? The code just tracks visitors from the time it was installed, and since you did not have it installed yesterday, you can't have any entries for yesterdays visitors...
    De gustibus non est disputandum.

  • #14
    Regular Coder
    Join Date
    Mar 2003
    Posts
    241
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry... but loool

    I mean no harm, but I find the last 2 replies amusing

  • #15
    Regular Coder
    Join Date
    May 2003
    Location
    34° 54' N 82° 13' W
    Posts
    996
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here it is --
    http://www.net-riches.com/includes/index.php?cat=home

    Bottom right hand corner under "Powered by PHP" image....
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!


  •  

    Posting Permissions

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