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
https://forums.phpfreaks.com/topic/107974-user-online-function/
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
https://forums.phpfreaks.com/topic/107974-user-online-function/#findComment-553483
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.