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 5 of 5
  1. #1
    Regular Coder
    Join Date
    Oct 2002
    Location
    Milwaukee, Wisconsin
    Posts
    123
    Thanks
    1
    Thanked 0 Times in 0 Posts

    sessions and cookies???

    hiya guys could someone please explain the whole sessoin thing or a good tutorial that would alow me to use a session with a cookie??i dont get sessions lol and my site is all cookieenabled but i wuld like to show online/offline status.. unless there is someway of doing ths with cookies...

  • #2
    New to the CF scene
    Join Date
    Mar 2003
    Location
    Bogotá, Colombia
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you use MySQL for your users, you could just do this:

    PHP Code:
    function updateLogin($userId) {
       
    mysql_query('update Users set lastLoginTime = NOW() where userId = "' $userId '"');
    }

    function 
    isOnline($userId$onlineTime 30) {
       
    $result mysql_query('select * from Users where userId = "' $userId '" and lastLoginTime > NOW() - interval ' $onlineTime ' second');
       
    $object mysql_fetch_object($result);
       
    mysql_free_result($result);
       return ((
    $object->userId) ? true false);

    This is kinda what I use, $userId is the id of the user (I assume your users have some sort of ID, it basically points to the unique ID each user should be given in any coherent user database) and $onlineTime is the time in seconds the query should check for, in this example, calling isOnline(3) would return true if the user whose userId = 3 has accessed the page in the past 30 seconds (and run the updateLogin($userId) function).

  • #3
    Regular Coder
    Join Date
    Oct 2002
    Location
    Milwaukee, Wisconsin
    Posts
    123
    Thanks
    1
    Thanked 0 Times in 0 Posts
    hey thank you man lots could i just ask tou what the -> does ive seen it in several places just ive never used it or learned it really doesnt it compare two things??

  • #4
    Regular Coder
    Join Date
    Feb 2003
    Location
    East Side/West Side
    Posts
    118
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It calls functions from within a class.

    PHP Code:
    class $foo {
          function 
    boo() {
          
    10;
          return 
    i;
       }

    Then it is called using the arrow operator

    PHP Code:
    $foo->boo(); 

  • #5
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Hope Im not going off topic here...

    That example you gave, kapil, you set an interval.

    I didn't quite get what you meant. Please could you explain it a bit more. How could you use it for a whos online thing?


  •  

    Posting Permissions

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