Added discrete users online in footer (from Wish List Forum) (New rerun)
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Tue, 13 Oct 2009 16:06:17 +0000 (16:06 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Tue, 13 Oct 2009 16:06:17 +0000 (16:06 +0000)
CHANGELOG.txt
admin/db/users_db.inc
sql/alter2.2.sql
sql/en_US-demo.sql
sql/en_US-new.sql

index 315a846c479772a047623975799206f04772cd70..d8f5f2a3598c694d5f0dfc42265d1e77641aa1cd 100644 (file)
@@ -24,7 +24,7 @@ $ -> Affected files
 $ /sales/inquiry/sales_orders_view.php
 
 13-Oct-2009 Joe Hunt
-+ Added discrete users online in footer (from Wish List Forum)
++ Added discrete users online in footer (from Wish List Forum) (New rerun)
 $ /admin/db/users_db.inc
   /sql/alter2.2.sql
   /sql/en_US-new.sql
index d7ac2e64acd35348acc078b2f566c29dbc362274..853de471160d41845cd9890bd611b0a7579904cc 100644 (file)
@@ -171,16 +171,34 @@ function show_users_online()
 
        $timestamp=time();
        $timeout=$timestamp-$timeoutseconds;
-       $ip = substr($_SERVER['REMOTE_ADDR'], 0, strrpos($_SERVER['REMOTE_ADDR'],"."));
-
-       // Add user to database
-       $loopcap = 0;
-       while($loopcap<3 && db_query("INSERT INTO ".TB_PREF."useronline VALUES('". $timestamp ."','". $ip ."','". $_SERVER['PHP_SELF'] ."')"))
-       {     // In geval van error
-           $timestamp = $timestamp+$ip{0}; 
-           $loopcap++;
+       /*
+       This will try to find out if user is coming behind proxy server. Why is this important?
+       If you have high traffic web site, it might happen that you receive lot of traffic
+       from the same proxy server (like AOL). In that case, the script would count them all as 1 user.
+       This function tryes to get real IP address.
+       Note that getenv() function doesn't work when PHP is running as ISAPI module
+       */
+       if (getenv('HTTP_CLIENT_IP')) {
+               $ip = getenv('HTTP_CLIENT_IP');
        }
-
+       elseif (getenv('HTTP_X_FORWARDED_FOR')) {
+               $ip = getenv('HTTP_X_FORWARDED_FOR');
+       }
+       elseif (getenv('HTTP_X_FORWARDED')) {
+               $ip = getenv('HTTP_X_FORWARDED');
+       }
+       elseif (getenv('HTTP_FORWARDED_FOR')) {
+               $ip = getenv('HTTP_FORWARDED_FOR');
+       }
+       elseif (getenv('HTTP_FORWARDED')) {
+               $ip = getenv('HTTP_FORWARDED');
+       }
+       else {
+               $ip = $_SERVER['REMOTE_ADDR'];
+       }
+       
+       // Add user to database
+       db_query("INSERT INTO ".TB_PREF."useronline (timestamp, ip, file) VALUES ('". $timestamp ."','". $ip ."','". $_SERVER['PHP_SELF'] ."')");
        //Remove users that were not online within $timeoutseconds.
        db_query("DELETE FROM ".TB_PREF."useronline WHERE timestamp<". $timeout);
 
index 9a50e75be87e54e555ec367e6b62385b1268a53e..a08cc39761a45209fda815e670f40bea18c04acf 100644 (file)
@@ -129,16 +129,16 @@ CREATE TABLE `0_tag_associations` (
   UNIQUE KEY(`record_id`,`tag_id`)
 ) TYPE=MyISAM;
 
-DROP TABLE IF EXISTS `0_usersonline`;
+DROP TABLE IF EXISTS `0_useronline` ;
 
 CREATE TABLE `0_useronline` (
+       `id` int(11) NOT NULL AUTO_INCREMENT ,
        `timestamp` int(15) NOT NULL default '0',
        `ip` varchar(40) NOT NULL default '',
        `file` varchar(100) NOT NULL default '',
-       PRIMARY KEY (`timestamp`),
-       KEY `ip` (`ip`),
-       KEY `file` (`file`) 
-) TYPE=MyISAM;
+       PRIMARY KEY `id` (`id`) ,
+       KEY (`timestamp`) 
+) TYPE=MYISAM AUTO_INCREMENT=1;
 
 ALTER TABLE `0_suppliers` ADD COLUMN `phone2` varchar(30) NOT NULL default '' AFTER `phone`;
 ALTER TABLE `0_cust_branch` ADD COLUMN `phone2` varchar(30) NOT NULL default '' AFTER `phone`;
index 44fe5ef854332c51c89e6b9e8066c9593e322e38..e53f281e0cc234873e18585a8515a6b9e699b871 100644 (file)
@@ -2098,14 +2098,14 @@ CREATE TABLE `0_tag_associations` (
 
 ### Data of table `0_tag_associations` ###
 
-DROP TABLE IF EXISTS `0_usersonline`;
+DROP TABLE IF EXISTS `0_useronline` ;
 
 CREATE TABLE `0_useronline` (
+       `id` int(11) NOT NULL AUTO_INCREMENT ,
        `timestamp` int(15) NOT NULL default '0',
        `ip` varchar(40) NOT NULL default '',
        `file` varchar(100) NOT NULL default '',
-       PRIMARY KEY (`timestamp`),
-       KEY `ip` (`ip`),
-       KEY `file` (`file`) 
-) TYPE=MyISAM;
+       PRIMARY KEY `id` (`id`) ,
+       KEY (`timestamp`) 
+) TYPE=MYISAM AUTO_INCREMENT=1;
 
index 9b91f300a43249cb7912296f63ce6e6d3277b147..90a2a329b71934a66b845c9835d7ab6ce783e0f0 100644 (file)
@@ -1840,14 +1840,14 @@ CREATE TABLE `0_tag_associations` (
 
 ### Data of table `0_tag_associations` ###
 
-DROP TABLE IF EXISTS `0_usersonline`;
+DROP TABLE IF EXISTS `0_useronline` ;
 
 CREATE TABLE `0_useronline` (
+       `id` int(11) NOT NULL AUTO_INCREMENT ,
        `timestamp` int(15) NOT NULL default '0',
        `ip` varchar(40) NOT NULL default '',
        `file` varchar(100) NOT NULL default '',
-       PRIMARY KEY (`timestamp`),
-       KEY `ip` (`ip`),
-       KEY `file` (`file`) 
-) TYPE=MyISAM;
+       PRIMARY KEY `id` (`id`) ,
+       KEY (`timestamp`) 
+) TYPE=MYISAM AUTO_INCREMENT=1;