Page 1 of 1

php settimeout call php function

Posted: Mon Aug 23, 2004 6:44 am
by fresh
hey,

I want to add a simple whos online script to my main page, but I dont want to refresh my whole page each time someone new logs in.. so I set up a cookie that gets there name and throws it in a cookie named active.. and then it checks for that cookie and if it's there it echo's the cookies value, which is their user name, like so:

Code: Select all

//set cookie
setcookie("active", $_SESSION['username'], time()+3600);
echo "Members Online<div>";
if (isset($_COOKIE["active"])) {
echo "".$_COOKIE["active"]."<div>";
} else {
//kill cookie
unset($_COOKIE["active"]);
}
Now is there a way I could reset or call this block of code, I guess throwing it in a function and calling it from javascript via settimeout() would work, but I have no idea how, I tried a couple things, and it wasnt reseting the script, I knew because the name would not appear, until I manually refreshed the page.. I need a way to do this auto, real fast and only once.. any ideas?? :)

Posted: Mon Aug 23, 2004 11:45 am
by Burrito
Fresh,

I don't think there is a way to dynamically update "who's online" w/o actually refreshing the page as it needs to get the "who's online" info from the server.

I have done something similar to what you're talking about and just put the "who's online" info in a small iframe at the top of all of my pages on the site. That iframe automatically refreshes every minute using a javascript setTimeout.

I can send you a link to the site on which I do this if you're interested so you can check it out....just lemme know.

Burr

Posted: Mon Aug 23, 2004 12:26 pm
by fresh
hey, thanks for replying.. I thought about using iframes, but I am afraid of how different browsers will react to it.. I know the size chages, so thats a concern.. I was think of makeing it an include and just sending people to a clone page of the index.. which by then they would have the cookie and be logged in, so the script would pick it up and echo it then.. i guess that's what I'll do.. thanks for the help and the offer though.. :)