PHP is open source scripting language. It\'s widely used to develop web applications.  Home Web Programming PHP Users Online
Your Ad Here

Users Online


Users OnlineFirst Run this SQL In your MYSQL database..

CREATE TABLE Totalonline (
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)
);

Next we will have to put this code on our page to show how many people are online! Its pretty easy.

<?php
//fill in your database,name,pw.
$server  =  "localhost" ;
$db_user  =  "username" ;
$db_pass  =  "password" ;
$database  =  "users" ;
$timeoutseconds  =  300 ;

//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 totalonline VALUES
('$timestamp','$REMOTE_ADDR','$PHP_SELF')" );
if(!( $insert )) {
print  "totalonline Insert Failed > " ;
}

//delete values when they leave
$delete  =  mysql_db_query ( $database ,  "DELETE FROM totalonline WHERE timestamp<$timeout" );
if(!( $delete )) {
print  "totalonline Delete Failed > " ;
}

//grab the results
$result  =  mysql_db_query ( $database ,  "SELECT DISTINCT ip FROM totalonline WHERE file='$PHP_SELF'" );
if(!( $result )) {
print  "totalonline 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 onlinen" );
} else {
print( "$user Users onlinen" );
}
?>


Author's URL: ViButX
Thank you for voting.
Rate this Materials:
Bad 
1 2 3 4 5 Excellent
print this page subscribe to newsletter subscribe to rss

Web programming � everything from the basics of visual design and architecture to the specifics of applications, graphics, and scripting. More Web Programming: Most Popular Materials | Fresh Materials | More PHP Tutorials at LearnPHP.org

Add comments to "Users Online"

Only registered users can write comment

No comments yet...