How can I know how many guests are browsing my website? Any help will be appreciated. Thank you in advance
Try many of the available web counters which can even track no of pages visited and no of users online. Ex - 1) histats.com 2) whos.amung.us Try these
Whipped something up real quick... This lets you display number of guests online within the last 5 minutes. <?php @mysql_connect('', '', '') && @mysql_select_db('') || die(mysql_error()); if (mysql_num_rows(mysql_query("SELECT * FROM `online` WHERE `online_ip` = '$_SERVER[REMOTE_ADDR]' AND `online_time` > UNIX_TIMESTAMP(NOW()) - 300"))) { mysql_query("UPDATE `online` SET `online_time` = UNIX_TIMESTAMP(NOW()) WHERE `online_ip` = '$_SERVER[REMOTE_ADDR]'"; } else { mysql_query("INSERT INTO `online` (`online_ip`, `online_time`) VALUES ('$_SERVER[REMOTE_ADDR]', UNIX_TIMESTAMP(NOW()))"); } $guests_online = mysql_num_rows(mysql_query("SELECT * FROM `online` WHERE `online_time` > UNIX_TIMESTAMP(NOW()) - 300")); ?> PHP: Include that in any page and use $guests_online to display them on any page. Execute this in MySQL for the table, and don't forge to fill in your MySQL info. CREATE TABLE `online` ( `online_ip` VARCHAR( 16 ) NOT NULL , `online_time` INT( 10 ) NOT NULL ) ENGINE = MYISAM Code (markup):
The best solution is to use AJAX and PHP to do that. Each time someone open ur index page add 1 into a flat file or db and when close subtract 1 (this can be made at window.close event) Cheers
Don't ask for reputation here at DP If people like it than they will rep you Also.. thanks for the script, I'm using it on my proxies now Greetz
you could also use register globals, although not very secure, it should do fine for tracking guests.
Also if you wanted you could modify Equaite's script and add another database field for the current page, then insert global variables on each page with a different name, then insert that value into the database depending on which page the user is on. You could then show how many users are on certain pages like home, about us, chat room etc. $_GLOBAL['pagename'] = "chatroom"; if($_GLOBAL['pagename'] == "chatroom"){ //INSERT chatroom into the page field }elseif($_GLOBAL['pagename'] == "homepage"){ //INSERT homepage into the page field } PHP: etc.etc.