First 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" ); } ?> |
Related Articles
- Users OnlineFirst Run this SQL In your MYSQL database..
- Page Navigation & Online Users & ChmodMany people have asked me how i got index2.php?page=link
Basically what happens, is where ever the folllowing code is put on your main php page, is where the the page link.php will go. - 3 Top Ways to Web Site DesignWhen online users visit a website, they initially form an opinion based on its appearance. At first, it will not really matter if your contents are of high quality or if you are offering excellent products and services.
- Should Your Join a Social Networking Website or Not?Social networking is defined as the grouping of individuals together into to specific groups, often like a small community or a neighborhood...
- Social Bookmarking: What is it?Social bookmarks are a way for internet users to store, organize, search, share and manage web pages on the internet that they find of interest....
- Set up Your Online PortfolioPlanning to set up your very own online portfolio? Very well, then you have to know first what
- Ten Fatal Mistakes That Make Web Sites StinkSince youll spend lots of time and money to create your web site, dont you want to make sure youre not making mistakes that at best irritate users, and at worst make you lose customers? After all, when you alienate users, you lose potential revenue. Who can afford that?
- Step Aside Pop-Ups, Hover Ads Are HereAs anyone involved in online marketing has learned in recent times, Pop-Up ads have developed a very negative connotation amongst Internet users the world over. Indeed, there has been an explosion in the availability of software and tools that are designed to block Pop-Up advertising...
- Professional SEO Companies: Do They Really Help Your Business?Boosting traffic in search engines does not only make your business website famous. It also advertises the business and helps you save on extra expenses.
- Popup: Hate em or Love emThis great article discusses the pros and cons of popups. The different types of popups and their relative trouble versus click rate makes for interesting reading. The response of users and designers to popups is interesting too.
