Jump to content

user online function


garry

Recommended Posts

Got another question for the helpful guys here at phpfreaks :)

 

I've got a function which controls the amount of users online, here it is:

 

function users_online($usersonline) {

if (isset($_SESSION['logged_in'])) {

	$ses = session_id();
	$time = time();
	$timech=$time-600;
	$userid = $_SESSION['user_id'];

	$result = mysql_query("SELECT * FROM usersonline WHERE session='$ses'");
	$num = mysql_num_rows($result);

	if ($num == "0"){

		$result1 = mysql_query("INSERT INTO usersonline (session, time, user_id)VALUES('$ses', '$time', $userid)");
		} 

	else {

		$result2 = mysql_query("UPDATE usersonline SET time='$time' WHERE session = '$ses'");
		}   

	$result3 = mysql_query("SELECT * FROM usersonline");  

	$usersonline = mysql_num_rows($result3);

	mysql_query("DELETE FROM usersonline WHERE time < $timech");

	return $usersonline;

	}

}

 

So basically what I want to know is how I can get this variable of $usersonline, outside of the function so I can use it on some pages that I want to. I've done some google and haven't found a whole lot so some help would be gladly appreciated!

Link to comment
Share on other sites

I'd rather use a function but I guess I could do that.

 

If anyone figures out how to do it with a function i'd still like to know!

 

Thanks for your help anyway

 

 

so when not just pull the result from the db instead at each page you want and echo it?  Is that what you want?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.