Tuesday, February 28, 2012

A simple method for displaying the number of users online and the page they are browsing : PHP/MySQL

This tutorial will demonstrate how you can create a very simple 'Users online' script that will tell you how many users are browsing your website and what page they are on.

First we create a table:

CREATE TABLE IF NOT EXISTS `users_online` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`ip` varchar(20) NOT NULL,
`timevisited` varchar(20) NOT NULL,
`page` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;

You can either execute this in your preferred MySQL administration tool (e.g. phpMyAdmin), or execute it in PHP: mysql_query($create); where $create is equal to the above SQL query. The timevisited column will take a timestamp (i.e. time()) in case you're wondering.

More... [1]

Links
  1. ^ More... (www.shaddeen.com)

No comments:

Post a Comment

Search This Blog