Call us Toll-Free:
1-800-218-1525
Live ChatEmail us

 Sponsors

Who's Online Script

Code Wizard, 12-30-2006
Simple who's online script. Just add the code to your page, edit the values that need editing and then make a table in MySQL. I tested it but there might be some problems so if you find one, let me know and I'll check it.

function online(){
/*This is the database info, use this to make a table in your database
CREATE TABLE online (
id int(10) NOT NULL,
username varchar(50) NOT NULL,
ip char(50) NOT NULL,
start char(50) NOT NULL
);
*/
#This starts the session to see who's online.
global $REMOT_ADDR,$HTTP_COOKIE_VARS;
#Cookie varuables for users.
$id=$HTTP_COOKIE_VARS['user_id'];
$username=$HTTP_COOKIE_VARS['username'];
#The time
$time=time();
#When the user is deleted from the database
$expirytime=$time-500;
#MySQL variables
$mysqlhost="localhost";
$mysqluser="user";
$mysqlpass="pass";
$mysqldata="database";
$mysqltable="online";
#Nothing below this needs editing.
$guest=0;
$mem=0;
$conn=mysql_connect("$mysqlhost","$mysqluser","$mysqlpass") or die (mysql_error());
mysql_select_db("$mysqldata") or die (mysql_error());
mysql_query("DELETE FROM $mysqltable WHERE (start < $expirytime)") or die (mysql_error());
if(!empty($id)){
mysql_query("DELETE FROM $mysqltable WHERE id='$id'") or die (mysql_error());
mysql_query("INSERT INTO $mysqltable (id,username,start) VALUES('$id','$username','$time')") or die (mysql_error());
}
else{
mysql_query("DELETE FROM $mysqltable WHERE ip='$REMOTE_ADDR'") or die (mysql_error());
mysql_query("INSERT INTO $mysqltable (id,username,ip,start) VALUES('0','guest','$REMOTE_ADDR','$time')") or die (mysql_error());
}
$whoison=mysql_query("SELECT * FROM $mysqltable") or die (mysql_error());
while($justwho=mysql_fetch_array($whoison)){
if($justwho['id']==0){
$guest=$guest+1;
}
else{
$mem=$mem+1;
$who.=$justwho[username];
}
}?>

Who's Online

Members: Guests:


Enjoyed this post?

Subscribe Now to receive new posts via Email as soon as they come out.

 Comments
Post your comments












Note: No link spamming! If your message contains link/s, it will NOT be published on the site before manually approved by one of our moderators.



About Us  |  Contact us  |  Privacy Policy  |  Terms & Conditions