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
    Feb 2005
    Posts
    663
    Thanks
    5
    Thanked 14 Times in 14 Posts

    Determine if User is on Page

    I've created two small image 'button's of green and red.

    I'd like to be able to have the image show green when the user is on a specific page (viewing a game) and red when they are not present.

    Is there a simple way to determine when a user is on a specific page?

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Store the page in the session, or database if you have a login system.

  • #3
    Regular Coder
    Join Date
    Feb 2005
    Posts
    663
    Thanks
    5
    Thanked 14 Times in 14 Posts
    Quote Originally Posted by Inigoesdr View Post
    Store the page in the session, or database if you have a login system.
    How would do that with a Session? I only want it to look at one specific page. I'm getting better at php, and thinking things through, but not sure on this one. It may be simplier than I'm making it to be though.

  • #4
    Regular Coder
    Join Date
    Mar 2007
    Location
    Quebec
    Posts
    261
    Thanks
    6
    Thanked 7 Times in 7 Posts
    Perhaps something like this - checking if a session has been set.
    PHP Code:
    if(isset($_SESSION['user_status'])){
      if(
    $_SESSION['user_status'] == "online"){
       
    user is online...
      }else{
       
    user is not online
      
    }

    You could incorporate it into a database too, and have the database updated when the user is online and when they leave the page.

  • #5
    Senior Coder
    Join Date
    Apr 2005
    Location
    Colorado, United States
    Posts
    1,208
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If you mean for others viewing the user's status, then you'll have to store it in a database. You can pretty easily store sessions in a database (see articles below) and then query the sessions table for status. I'm sure you can come up with the logic to set a session variable for in game or not and the code to deserialize the session information.

    http://www.raditha.com/php/session.php
    http://www.developertutorials.com/tu...711/page1.html
    "$question = ( to() ) ? be() : ~be();"


  •  

    Posting Permissions

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