X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   IP Addresses in Users Online for all users (https://forum.x-cart.com/showthread.php?t=16571)

hamid 09-13-2005 02:45 PM

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.

balinor 09-14-2005 04:25 AM

Nice, lots of people have asked for this. Thanks for sharing!

hamid 09-14-2005 09:32 AM

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.

Dongan 09-15-2005 09:00 PM

good. Thanx for sharing...

2019 09-16-2005 04:09 AM

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

hamid 09-16-2005 03:45 PM

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?

2019 09-17-2005 12:22 PM

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.
:?

MythNReality 09-21-2005 04:13 PM

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...?

anandat 09-22-2005 04:38 AM

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.

hamid 09-23-2005 03:42 AM

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!


All times are GMT -8. The time now is 12:06 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.