SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Somewhere in this vast universe
    0 Post(s)
    0 Thread(s)

    Advanced session and cookie handlers.

    I still can't figure this out. I don't know how boards like phpbb2 knows what messages and forums have new posts since the last time someone logged on. If you update the session every time he logs on then there new icon would never appear because the updated time will be greater than the last post for a forum or a thread. How are there session handles written?

    How can I record the time whenever a users leaves my page for another page or closes the browser?

    Can anyone give me a good explanation and some code?

  2. #2
    That's Right. notepad_coder's Avatar
    Join Date
    Apr 2002
    0 Post(s)
    0 Thread(s)
    My solution for this would be to have a 'last login' field in the database and check posts as 'new' that have a newer timestamp than the 'last login' field. This code isn't for this, but it gives the same idea.
    PHP Code:
     function logip() {
    $ip $_SERVER['REMOTE_ADDR'];    
    $duration 2;
    $old mktime(date("G"), (date("i")-$duration), date("s"), date("n"), date("j"), date("Y"));
    mysql_query("UPDATE logs SET last='0' WHERE last<'".$old."'");
    $new = (int) mysql_num_rows(mysql_query("SELECT * FROM logs WHERE ip='".$ip."'"));
         if (
    $new == 0) {
    mysql_query("INSERT INTO logs VALUES('".$ip."', '".mktime()."', '".mktime()."')") or die(mysql_error());
         } else {
    mysql_query("UPDATE logs SET visit=last, last='".mktime()."' WHERE ip='".$ip."'") or die(mysql_error());
         return (int) 
    mysql_result(mysql_query("SELECT COUNT(*) FROM logs WHERE last>'0'"), 0);
    I use this to track 'active visitors' on my site, it updates their timestamp everytime they visit a page that runs the logip() function and changes all timestamps to 0 that are older than 2 minutes. I hope this helps give an idea. I will make a script a little later describing it better.
    - the lid is off the maple syrup again!


Posting Permissions

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