PDA

View Full Version : if statement showing online..



insanemonkey
10-11-2007, 04:20 PM
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.

Twey
10-11-2007, 04:53 PM
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?

insanemonkey
10-11-2007, 05:05 PM
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?

Twey
10-11-2007, 05:49 PM
You still haven't showed what $session looks like.

insanemonkey
10-11-2007, 06:27 PM
I have a whole seperate file for sessions...

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

1340

insanemonkey
10-11-2007, 11:12 PM
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?

Twey
10-11-2007, 11:43 PM
Why not just check $session->logged_in?

insanemonkey
10-12-2007, 12:32 AM
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...

Twey
10-12-2007, 01:36 AM
Tell me what you're trying to do in English, at the level of the code.

insanemonkey
10-12-2007, 01:39 AM
lol sorry...
here is what I have been working on, but this only shows me if im online not the user...



$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..