Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

IP Addresses in Users Online for all users

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 09-13-2005, 02:45 PM
 
hamid hamid is offline
 

Senior Member
  
Join Date: Apr 2004
Posts: 107
 

Default IP Addresses in Users Online for all users

With this mod you can see the IP Address of all users (including "Unregistered User") in the Users Online page.

I've only tested this mod with v4.0.14, but it should work just as well in 4.0.x.

It's really easy to implement this modification, but remember to backup your files before you make any changes.

What the following changes do is:

1. Creates a new entry in session data called session_ip
2. Saves users IP address in session_ip
3. Calls session_ip data in the .tpl file

You have to change 3 files:

1. auth.php
2. xcart>modules>Users_online>stats.php
3. xcart>skin1>modules>Users_online>stats.tpl

On (or around) line 64 in auth.php look for:


Code:
*********************************************** if(!empty($active_modules['Users_online'])) { x_session_register("current_url_page"); x_session_register("current_date"); x_session_register("session_create_date"); $current_url_page = $php_url['url'].($php_url['query_string']?"?".$php_url['query_string']:""); if(empty($session_create_date)) $session_create_date = time(); $current_date = time(); } *********************************************** And change it to: *********************************************** if(!empty($active_modules['Users_online'])) { x_session_register("session_ip"); x_session_register("current_url_page"); x_session_register("current_date"); x_session_register("session_create_date"); $current_url_page = $php_url['url'].($php_url['query_string']?"?".$php_url['query_string']:""); if(empty($session_create_date)) $session_create_date = time(); $current_date = time(); $session_ip = getenv('REMOTE_ADDR'); } ***********************************************

Then on line 50 in xcart>modules>Users_online>stats.php look for:

Code:
*********************************************** $vars = array("login", "login_type", "cart", "current_date", "current_url_page", "session_create_date"); *********************************************** And change it to: *********************************************** $vars = array("login", "login_type", "cart", "current_date", "current_url_page", "session_create_date", "session_ip"); ***********************************************

In the same file (stats.php), look for the following on line 94:

Code:
*********************************************** $rec['session_create_date'] = $data['session_create_date']+$config["General"]["timezone_offset"]; $statistics[] = $rec; *********************************************** And change it to: *********************************************** $rec['session_create_date'] = $data['session_create_date']+$config["General"]["timezone_offset"]; $rec['session_ip'] = $data['session_ip']; $statistics[] = $rec; ***********************************************

And finally you have to put "IP: {$v.session_ip}" into xcart>skin1>modules>Users_online>stats.tpl

On line 20 look for:

Code:
*********************************************** <TD bgcolor="#FFFFFF" nowrap valign="top">{if $v.userinfo ne ''}{$v.userinfo.firstname} {$v.userinfo.firstname}{if $v.userinfo.status eq 'A'} ({$lng.lbl_anonymous_customer}){/if}{else}{$lng.lbl_unregistered_customer}{/if}</TD> *********************************************** And change it to: *********************************************** <TD bgcolor="#FFFFFF" nowrap valign="top">{if $v.userinfo ne ''}{$v.userinfo.firstname} {$v.userinfo.firstname}{if $v.userinfo.status eq 'A'}({$lng.lbl_anonymous_customer}){/if}{else}{$lng.lbl_unregistered_customer}{/if} IP: {$v.session_ip}</TD> ***********************************************

That's all the changes done, now go to the Users Online section [in Admin>Statistics>Users Online] and the IP Address of customers currently on your site should appear underneath their names.

If you reload your Users Online page at regular intervals you can watch how your customers navigate your site.
Reply With Quote

The following 4 users thank hamid for this useful post:
cherkes (04-30-2010), Dan.roh (02-12-2010), jully147 (05-08-2009), microdaq (03-11-2011)
  #2  
Old 09-14-2005, 04:25 AM
 
balinor balinor is offline
 

Veteran
  
Join Date: Oct 2003
Location: Connecticut, USA
Posts: 30,253
 

Default

Nice, lots of people have asked for this. Thanks for sharing!
__________________
Padraic Ryan
Ryan Design Studio
Professional E-Commerce Development
Reply With Quote
  #3  
Old 09-14-2005, 09:32 AM
 
hamid hamid is offline
 

Senior Member
  
Join Date: Apr 2004
Posts: 107
 

Default

Thanks balinor, yeah I hope it helps a few people out.

I was really disappointed when I realised that xcart didnt have this functionality - I thought it was part of the standard package.

OSCommerce has this feature as standard, and in my opinion it should be standard in xcart too.

I think it's quite a valuable feature because it allows to you track your customers as they move around.

In my experience at least, I find that most customers are unregistered until they are actually ready to buy something, at which point they will register. So for the majority of users on the site you dont really get any valuable insight into what they're doing - all you see is that 'someone' is on 'a particular page'. And if you have a lot of unregistered users on your site there is no way of keeping track of a specific user.

Whereas when you can see their ip adress, the unregistered user loses some of their anonymity, so now you can see that user-1 was on the home page, now they've gone to cat-x, then product-y etc. So you are seeing the movements of your potential customers almost as it happens.

Watching customers as they surf your site and buy (or not buy) in this way can help you lotate bottlenecks or problems in your site to help streamline the buying process that you have implemented.

Incidentally, I also added another feature to this mod which displays the previous page the customer was on before they arrived at the current page.

If anyone's interested I'll post that mod as well.
Reply With Quote
  #4  
Old 09-15-2005, 09:00 PM
  Dongan's Avatar 
Dongan Dongan is offline
 

X-Wizard
  
Join Date: Jul 2005
Location: www.mercuryminds.com
Posts: 1,531
 

Default

good. Thanx for sharing...
Reply With Quote
  #5  
Old 09-16-2005, 04:09 AM
  2019's Avatar 
2019 2019 is offline
 

Advanced Member
  
Join Date: Dec 2004
Posts: 76
 

Default

thanx great! but not working for me .14.
i didt the 3 steps login to my site but i dont see any ip's all is blank!


extra extra extra
is it possible to see the referral information?
thank you!

also can you post that mod too
__________________
// x-cart 4.1.9

X-CART CSS SKIN
XC SEO
IP Addresses in Users Online for all users
Color coded order status
Reply With Quote
  #6  
Old 09-16-2005, 03:45 PM
 
hamid hamid is offline
 

Senior Member
  
Join Date: Apr 2004
Posts: 107
 

Default

Hi 2019

It's a shame that it's not working for you - but if you have followed the instructions above and you are running 4.0.14 (although it probably works on any 4.0.x), then I really don't know why it's not working without seeing your code.

This was the first mod I've posted, so to be honest I dont know if it works on anyone elses system. It works on mine, so in theory it should work with others too.

I'm not an expert, but in order to try to make it work you could try the following:

1. Some servers have a problem with the 'getenv' function, so in my modification of auth.php, change

$session_ip = getenv('REMOTE_ADDR');

to:

$session_ip = $HTTP_SERVER_VARS['REMOTE_ADDR'];

Then upload the ammended file and see if the IP addresses appear in your Users Online page.

To be honest, I think it's generally accepted that it's better practice to use $HTTP_SERVER_VARS rather than getenv anyway

If anyone else has tried this mod... did it work?
Reply With Quote
  #7  
Old 09-17-2005, 12:22 PM
  2019's Avatar 
2019 2019 is offline
 

Advanced Member
  
Join Date: Dec 2004
Posts: 76
 

Default

dear hamid,

well i tried $session_ip = $HTTP_SERVER_VARS['REMOTE_ADDR'];
didn't solve it

i can not see the ip's

i can not understand if this is working for you not working for me.
__________________
// x-cart 4.1.9

X-CART CSS SKIN
XC SEO
IP Addresses in Users Online for all users
Color coded order status
Reply With Quote
  #8  
Old 09-21-2005, 04:13 PM
  MythNReality's Avatar 
MythNReality MythNReality is offline
 

X-Adept
  
Join Date: Mar 2005
Location: S. Cali
Posts: 403
 

Default

I could not find the correspondence code under those two files:

1. Auth.php
2. Users onine>stats.php

Not sure because of the version or...?
__________________
_____________
Capture Your Mini-Me Look!

- X-CART Gold (Current Version) V4.6
- Reboot
- CDSEO
Reply With Quote
  #9  
Old 09-22-2005, 04:38 AM
 
anandat anandat is offline
 

X-Adept
  
Join Date: Jan 2004
Posts: 914
 

Default

I am on 4.0.12 & I also can't find 2nd step code in stats.php

following is my stats.php

Code:
if ( !defined('XCART_SESSION_START') ) { header("Location: error_message.php?permission_denied"); die("Access denied"); } $sesses = func_query("SELECT sessid, is_registered FROM $sql_tbl[users_online] WHERE usertype = 'C'"); $statistics = array(); if($sesses) { foreach($sesses as $s) { $data = func_query_first("SELECT data, expiry FROM $sql_tbl[sessions_data] WHERE sessid = '$s[sessid]'"); if(empty($data['data'])) continue; $rec = array("last_date" => $data['expiry']); $data = unserialize($data['data']); if(!empty($data['login']) && $data['login_type'] != 'C') continue; if(!empty($data['login'])) $rec['userinfo'] = func_userinfo($data['login'], 'C'); if(!empty($data['cart']['products'])) $rec['products'] = $data['cart']['products']; $rec['current_date'] = $data['current_date']+$config["General"]["timezone_offset"]; $rec['current_url_page'] = $data['current_url_page']; $rec['session_create_date'] = $data['session_create_date']; $statistics[] = $rec; } } ?>

Could you please me what excatly I will have to change in this file.
__________________
X-Cart: 4.7.7 LIVE
Skin:Ultra by xcartmods.co.uk
X-cart Modules: | ACR, Rich Google Search, Customer Testimonials | Cloud Search, | Websitecm: CDSEO (2.1.9)
---------------
Server: Linux
php: 5.3
mysql: 5.0.89
----------------
Reply With Quote
  #10  
Old 09-23-2005, 03:42 AM
 
hamid hamid is offline
 

Senior Member
  
Join Date: Apr 2004
Posts: 107
 

Default

Well, I had a look at an old x-cart distributive (v4.0.9), and it seems that x-cart changed stats.php slightly from 4.0.14 onwards (I think) - and you are right, the part of the code you need to change is not there.

I dont know enough about php to be able to tell you what to change to in your version of stats.php to get this mod to work - but I can suggest a couple of things that you can try.

First thing to try is, in Users_online> stats.php - forget about the first part of the mod for that file, and just apply the second part of the mod instead, ie:

Find:

Code:
*********************************************** $rec['session_create_date'] = $data['session_create_date']+$config["General"]["timezone_offset"]; $statistics[] = $rec; *********************************************** And change it to: *********************************************** $rec['session_create_date'] = $data['session_create_date']+$config["General"]["timezone_offset"]; $rec['session_ip'] = $data['session_ip']; $statistics[] = $rec; ***********************************************

Change all the other files according to the instructions for the rest of the mod, upload, clear templates cache, and test to see if that works.

If that doesn't work, then the only thing I can suggest is you could try to replace your stats.php with the modified one from 4.0.14 and see if that works.

So change your stats.php file to this:

Code:
*********************************************** if ( !defined('XCART_SESSION_START') ) { header("Location: error_message.php?permission_denied"); die("Access denied"); } $sesses = func_query("SELECT sessid, is_registered, expiry FROM $sql_tbl[users_online] WHERE usertype = 'C'"); $statistics = array(); if($sesses) { foreach($sesses as $s) { $data = array(); if ($use_sessions_type == 3 || $use_sessions_type == 2) { $data = func_query_first("SELECT data FROM $sql_tbl[sessions_data] WHERE sessid = '$s[sessid]'"); } elseif ($use_sessions_type == 1) { $old_sessid = $XCARTSESSID; x_session_id($s['sessid']); x_session_start($s['sessid']); $vars = array("login", "login_type", "cart", "current_date", "current_url_page", "session_create_date", "session_ip"); $data = array("data" => array()); $_s = array(); foreach ($vars as $v) { $_s[$v] == $$v; x_session_register($v); $data['data'][$v] = $$v; } x_session_id($old_sessid); x_session_start($old_sessid); foreach ($vars as $v) { x_session_register($v); $$v == $_s[$v]; } } if(empty($data['data'])) continue; $rec = array("last_date" => $s['expiry']); if ($use_sessions_type == 3) { $data = unserialize($data['data']); } elseif ($use_sessions_type == 2) { $tmp = explode("|", $data['data']); $data = array(); $last_name = array_shift($tmp); foreach ($tmp as $k => $v) { if (($pos = strrpos($v, ";")) === false) break; $pos2 = strrpos($v, "}"); if ($pos2 > $pos) $pos = $pos2; $data[$last_name] = unserialize(substr($v, 0, $pos+1)); $last_name = substr($v, $pos+1); } } elseif ($use_sessions_type == 1) { $data = $data['data']; } if(!empty($data['login']) && $data['login_type'] != 'C') continue; if(!empty($data['login'])) $rec['userinfo'] = func_userinfo($data['login'], 'C'); if(!empty($data['cart']['products'])) $rec['products'] = $data['cart']['products']; $rec['current_date'] = $data['current_date']+$config["General"]["timezone_offset"]; $rec['current_url_page'] = $data['current_url_page']; $rec['session_create_date'] = $data['session_create_date']+$config["General"]["timezone_offset"]; $rec['session_ip'] = $data['session_ip']; $statistics[] = $rec; } } ***********************************************

To be honest, if the first method (above) didn't work, then I wouldn't have high hopes that this latter method will work, but it's definitely worth a try - just make sure you have a backup of your files in case it doesn't work and you need to revert.

To MythNReality: the code in auth.php is there in v4.0.9, so it should be there in 4.0.12 as well. Just search for 'Users_online' in your copy of auth.php - there is only one instance of it in the whole of the file, so the code you are looking for should be right there (unless you've modified your auth.php and somehow gotten rid of it - if you have an unmodified copy of auth.php do a search in that and see if it's there).

I hope this helps!
Reply With Quote

The following user thanks hamid for this useful post:
New York (06-24-2014)
Reply
   X-Cart forums > X-Cart 4 > Dev Questions


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 11:01 PM.

   

 
X-Cart forums © 2001-2020