Results 1 to 10 of 10

Thread: if statement showing online..

  1. #1
    Join Date
    Oct 2005
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default if statement showing online..

    sorry I didn't know what to put for title...

    on my website under the user page I would like to make it show if the user is online, like myspace.

    I am just startingto learn a little about the else and if statements so please help me out..

    can you help fix this,


    if(strcmp($session->username,$req_user) == true){
    echo "Online!";
    } else {
    echo "Offline!";
    }

    I tried this and couldn't get it working..

    I just want to display if the user is online or offline.
    Hey new design new look, goto xudas for personal webdsign help.. (:

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    HTTP is a stateless protocol: the browser (often) closes the connection after every request. As such it's not actually possible to tell whether a user is online or not at a given moment; sites such as this one work by saying a user is online if they've made a request within the last x minutes.ß♯sz

    That said, where are the $session object and $req_user variable defined?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Oct 2005
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    those are defined before the coding..

    in example ill show you really quick...

    when a user logs into my website, and when a different user gotos his account page, I want to see if the user is logged in and then show if they are...

    here is what my coding looks like... using session and req user


    <?php

    $req_user = trim($_GET['user']);
    if(!$req_user || strlen($req_user) == 0 ||
    !eregi("^([0-9a-z])+$", $req_user) ||
    !$database->usernameTaken($req_user)){
    die("Username not registered");
    }

    $req_user_info = $database->getUserInfo($req_user);

    ?>

    the code goes on after that but you don't need that..
    ???? thanks for the reply

    if I cant do that with the if statement or whatever, then how would I be able to do it pulling if user was logged in within last 5 minutes?
    Hey new design new look, goto xudas for personal webdsign help.. (:

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    You still haven't showed what $session looks like.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Oct 2005
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    I have a whole seperate file for sessions...

    I uploaded it as a attachment into a text file.. but session is long.. so..

    Attachment 1340
    Hey new design new look, goto xudas for personal webdsign help.. (:

  6. #6
    Join Date
    Oct 2005
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    well what could i attach or make something so I could get username and so it would show user online..

    what would I add to sessions?

    or could I just use cookies?
    Hey new design new look, goto xudas for personal webdsign help.. (:

  7. #7
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Why not just check $session->logged_in?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  8. #8
    Join Date
    Oct 2005
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    can you help me.. like i dont no what I would do...

    something like this, i really don't know how to use if statement,..

    $req_user = trim($_GET['user']);
    if($session->logged_in,$req_user){
    echo blah
    } else {
    echo blah
    }

    is this right? I couldn't get it to work...
    Hey new design new look, goto xudas for personal webdsign help.. (:

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Tell me what you're trying to do in English, at the level of the code.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Oct 2005
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    lol sorry...
    here is what I have been working on, but this only shows me if im online not the user...

    Code:
    $req_user = trim($_GET['user']);
    if(!$req_user || strlen($req_user) == 0 ||
       !eregi("^([0-9a-z])+$", $req_user) ||
       !$database->usernameTaken($req_user)){
       die("Username not registered");
    }
    
    $req_user_info = $database->getUserInfo($req_user);
    
    
    
    if(strcmp($req_user['username']) == 0){
    echo "online";
    } else {
    echo "offline";
    }
    when I veiw this on other users account it shows that they are online meaning its getting if im online not the user...

    I am so confused and not confused..
    Hey new design new look, goto xudas for personal webdsign help.. (:

Bookmarks

Posting Permissions

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