Riseykins Posted October 4, 2008 Share Posted October 4, 2008 I've been looking for one for a while, but none seem to work. Plus, I'm a n00b so a lot of the tutorials don't make sense to me! If anyone here knows of a good one, please let me know! Quote Link to comment Share on other sites More sharing options...
Riseykins Posted October 4, 2008 Author Share Posted October 4, 2008 Can anyone help? Quote Link to comment Share on other sites More sharing options...
dropfaith Posted October 4, 2008 Share Posted October 4, 2008 http://www.google.com/url?sa=t&source=web&ct=res&cd=1&url=http%3A%2F%2Fwww.sim-php.info%2Fusers-online-script.php&ei=XI7nSLDeNqTmMPLJxfUL&usg=AFQjCNFuQgcqF1iWrMRYP_-sD7vEOEvwNA&sig2=9cTqMC-DC-K7gc-4TSdVIA Quote Link to comment Share on other sites More sharing options...
Riseykins Posted October 4, 2008 Author Share Posted October 4, 2008 When I tried to execute the stuff it said to, it didn't work. Quote Link to comment Share on other sites More sharing options...
ghqwerty Posted October 4, 2008 Share Posted October 4, 2008 Step1: Creating the database create a new database called 'users', with 3 fields inside a table. These fields are timestamp, ip and file. Name the table useronline by the way. Now with the form on the PhpMyAdmin page, add the following code: CREATE TABLE useronline ( timestamp int(15) DEFAULT '0' NOT NULL, ip varchar(40) NOT NULL, file varchar(100) NOT NULL, PRIMARY KEY (timestamp), KEY ip (ip), KEY file (file) ); Step 2: The PHP Script <?php //Put your basic server info here $server = "localhost"; //normally localhost $db_user = "username"; //your MySQL database username $db_pass = "password"; //your MySQL database password $database = "users"; $timeoutseconds = 300; //this is where PHP gets the time $timestamp = time(); $timeout = $timestamp-$timeoutseconds; //connect to database //$server = localhost probably //$db_user = your MySQL database username //$db_pass = //your MySQL database password mysql_connect($server, $db_user, $db_pass); //insert the values $insert = mysql_db_query($database, "INSERT INTO useronline VALUES ('$timestamp','$REMOTE_ADDR','$PHP_SELF')"); if(!($insert)) { print "Useronline Insert Failed > "; } //delete values when they leave $delete = mysql_db_query($database, "DELETE FROM useronline WHERE timestamp<$timeout"); if(!($delete)) { print "Useronline Delete Failed > "; } //grab the results $result = mysql_db_query($database, "SELECT DISTINCT ip FROM useronline WHERE file='$PHP_SELF'"); if(!($result)) { print "Useronline Select Error > "; } //number of rows = the number of people online $user = mysql_num_rows($result); //spit out the results mysql_close(); if($user == 1) { print("$user user online\n"); } else { print("$user users online\n"); } ?> I've tried to make that code as simple as possible to understand. The //comment won't affect the script, so you can remove those if you want. The script basically works like this. It receives server information and gets he time. In mySQl it fills in the values of the person online and puts up a message if it failed. When the user leaves mySQL deletes the user and displays a message if it failes. Quote Link to comment Share on other sites More sharing options...
Riseykins Posted October 4, 2008 Author Share Posted October 4, 2008 Thanks! It seems to work. It was really easy to understand, too. Quote Link to comment Share on other sites More sharing options...
Riseykins Posted October 4, 2008 Author Share Posted October 4, 2008 It seems to be saying that 1 person is online and that's all. :S Quote Link to comment Share on other sites More sharing options...
ghqwerty Posted October 4, 2008 Share Posted October 4, 2008 because youre trying it dfrom the same ip are you doing on localhost or on a proper host if i was to say log on it would say 2 it does it on the ip so even if you logged in with 10 people from your computer they would all have the same ip so it would only show 1 Quote Link to comment Share on other sites More sharing options...
Riseykins Posted October 4, 2008 Author Share Posted October 4, 2008 I put it live on my site and another counter is saying 4 is online whereas this always says 1... Quote Link to comment Share on other sites More sharing options...
ghqwerty Posted October 4, 2008 Share Posted October 4, 2008 whats your site ill login Quote Link to comment Share on other sites More sharing options...
Riseykins Posted October 5, 2008 Author Share Posted October 5, 2008 It's http://www.burningviolet.com/ Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.