Jump to content

users online


Kingy

Recommended Posts

i have a users online script, that will insert a users ip and a 3 minute timestamp. obviously if they arn't there in 3 minutes that user is now offline. it works fine, but what i am going to do now is also insert the $_SESSION[username] to tell if the user is a member or not.

 

i no how to insert it and what not but how do i make it so its like:

Users online: 12

Members online: 5

 

for the users online i have

$usersonline = mysql_query("SELECT DISTINCT ip FROM usersonline") or die(mysql_query());

 

but how do i get it so it selects the rows that have a username in them?

Link to comment
https://forums.phpfreaks.com/topic/90273-users-online/
Share on other sites

so do something like

 

if(isset($_SESSION[username])) {

 

insert into users online (timestamp, ip, registered) values (..., ....., 1)

 

} else {

 

insert into users online (timestamp, ip, registered) values (..., ....., 0)

 

}

 

and then just select all rows where registered = 1 ? 

Link to comment
https://forums.phpfreaks.com/topic/90273-users-online/#findComment-462842
Share on other sites

Well I think you might be able to get away with this

<?php
$q = "Insert into `user_online` (timestamp,ip,registered) values('','',$_SESSION['UserID'])";
?>

If registered is a Bool and the value of $_SESSION['UserID'] is not null or 0 then the user will be "True" and it should insert a 1 not a 0

 

and if you default it to 0 and you insert $_SESSION['UserID'] it will insert '' when it is undefined and result in it going to a default value of 0.

 

So do it like I gave and make registered be a Bool field default 0

Link to comment
https://forums.phpfreaks.com/topic/90273-users-online/#findComment-462844
Share on other sites

Warning: Wrong parameter count for mysql_query() on line 24

 

$registered = isset($_SESSION['username']) ? $_SESSION['username'] : '';

$usersonlineinsert = mysql_query("INSERT INTO usersonline (timestamp, ip, registered) VALUES ('$timestamp','$ip', '$registered')") or die(mysql_query());

Link to comment
https://forums.phpfreaks.com/topic/90273-users-online/#findComment-462857
Share on other sites

yeah wasn't sure if it take it so try

<?php
if(isset($_SESSION['username'])){$register = 1;} 
$q = "INSERT INTO `usersonline` (timestamp, ip, regsitered) VALUES('".$timestamp."', '".$ip."', '".$register."')";
$useronlineinsert = mysql_query($q) or die(Mysql_error()."<Br /><br />".$q);
?>

Link to comment
https://forums.phpfreaks.com/topic/90273-users-online/#findComment-462880
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.