Go Back   Gaming Gutter > Non-Gaming > Programming > Source Code


Source Code - Have a source code/project files you want to post? Do so here.

» Site Navigation
» Home
» FAQ
» Log in
User Name:

Password:

Not a member yet?
Register Now!
» Advertisement
» Recent Threads
Go to first new post My formal on Friday
11-17-2008 05:12 AM
by Bex
Last post by Bex
Today 10:17 PM
11 Replies, 50 Views
Go to first new post Paypal help?
Today 10:11 PM
by 1x1
Last post by 1x1
Today 10:11 PM
0 Replies, 1 Views
Go to first new post NextGenWarrior = scammer
Yesterday 10:29 PM
by Peanuts
Last post by Jakious
Today 10:08 PM
13 Replies, 121 Views
Go to first new post Do you think smoking is...
08-16-2008 07:09 PM
Last post by kemoomek
Today 10:07 PM
249 Replies, 2,602 Views
Go to first new post People that use...
10-26-2008 01:50 PM
by kiasyn
Last post by Jakious
Today 10:05 PM
23 Replies, 664 Views
Reply
 
LinkBack Thread Tools Display Modes

 [PHP] Show Users Online
Old 12-10-2006, 03:15 PM   #1 (permalink)
emit
Guest

 
Posts: n/a
GPoints: 0 [Check]
iTrader: / %
Post [PHP] Show Users Online

PHP - SHOW USERS ONLINE

Possibly the most sought after PHP script - and here it is!
For this tutorial you will need a MySQL database, as the stats will be hosted on your own server. Also, this tutorial was written assuming you have phpMyAdmin (Download it!).
In phpMyAdmin, click on your database then click on SQL at the top. Type this in the box and click 'Go':
PHP Code:
CREATE TABLE `useronline` (

  `
timestampint(15NOT NULL default '0',

  `
ipvarchar(40NOT NULL default '',

  `
filevarchar(100NOT NULL default '',

  
PRIMARY KEY  (`timestamp`),

  
KEY `ip` (`ip`),

  
KEY `file` (`file`)


Now just copy this code where you want the stats to appear:
PHP Code:

  <?



//online

$server "YOUR HOST"// usually localhost

$db_user "USERNAME"

$db_pass "PASSWORD"

$database "DATABASE"

$timeoutseconds 300// length of gaps in the count



//get the time

$timestamp time(); 

$timeout $timestamp-$timeoutseconds



//connect to database

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





//delete values when they leave

$delete mysql_db_query($database"DELETE FROM useronline WHERE timestamp<$timeout"); 

if(!(
$delete)) { 

    print 
""





//grab the results

$result mysql_db_query($database"SELECT DISTINCT ip FROM useronline WHERE file='$PHP_SELF'"); 

if(!(
$result)) { 

    print 
""





//number of rows = the number of people online

$user mysql_num_rows($result); 

if(!(
$user)) {

print(
"ERROR: " mysql_error() . "\n");

}





//spit out the results

mysql_close(); 

print(
"$user"); 



?>
That's it!
  Reply With Quote
Reply

Bookmarks



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Powered by vBadvanced CMPS v3.0 RC2

All times are GMT -7. The time now is 10:19 PM.


vBulletin skin developed by: eXtremepixels
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The contents of this webpage are copyright © 2006-2008 GamingGutter.com. All Rights Reserved.

Page generated in 0.08665800 seconds (100.00% PHP - 0% MySQL) with 17 queries