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