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!

anandat 09-23-2005 06:47 AM

Dear Hamid,

Thanks a million for the code for old 4.0 ...it's working like a charm :D

hamid 09-23-2005 07:38 AM

Excellent!

Now just send me your address and I'll send you my invoice.

Just kidding of course :D

I'm glad I could help!

For the benefit of other users, what did you do to get it to work for 4.0.12?

Did you use the whole of the code for 4.0.14 that I provided or did you just change that little bit of code in your stats.php file?

anandat 09-23-2005 08:13 AM

Invoice :?: for what :?: ....... just kidding man :wink:

I did following

1) I made changes in auth.php as per your step 1

2) In my second step I did following as per your instruction for Users Online--> stats.php


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;

***********************************************


3) In my third step I made following changes in stats.tpl.


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>

***********************************************


Hamid....thanks once again for your help :)

2019 09-24-2005 07:10 AM

Big Thanx!
Fixing Stats.php helped me working!
4.0.14

Bella Forma 10-21-2005 02:24 PM

Big thanks from me too!

I have a sneaking suspicion a competitor is racking up charges for me by clicking on Overture and Adwords.

This lovely little mod will help me to have at least some idea if the same person is on my site all the time :)

shipmerchant 10-23-2005 06:58 PM

Nice mod. I dont have the users online menu activated on the customers page, only on admin. My question is can this be added to the customer page down at the botton of the page? I have seen this on sone Zen Cart websites and it looks really great. But not sure where to start.


Can someone assist me with this please?

:(

MythNReality 11-05-2005 11:43 PM

Thanks Hamid and anandat. Great works...now my cart is getting better and better (and more complicated) each day... :lol:

BoomBoomBap 12-04-2005 07:32 PM

Great mod. Works like a charm - thanks !

thundernugs 02-24-2006 02:10 PM

pardon me if i misread, but does anyone have this working for 4.0.17?

if so, did you follow the initial mod posted or one of the different iterations posted afterwards?

i tried the initial post, but my ip address came up blank

thanks in advance!

mike

denlem 02-24-2006 03:28 PM

Original code works great for me in 4.0.17

thundernugs 02-25-2006 10:46 PM

yep, the original code works great in 4.0.17 (thanks denlem)

i also added this little tidbit into stats.tpl allows for an easy link to check the whois info of the IP addresses of your users online

Code:

IP: {$v.session_ip}

thanks for the mod!

mike

Jerrad 04-09-2006 05:20 AM

Sounds like a great mod - thanks for that! :D

Just wondering if it would be possible to do the same for the customer side of the shop, so that not only the IP-address from registered
but also from a unregistered visitor is displayed?

cliffo4 04-09-2006 12:54 PM

Quote:

Originally Posted by thundernugs
yep, the original code works great in 4.0.17 (thanks denlem)

i also added this little tidbit into stats.tpl allows for an easy link to check the whois info of the IP addresses of your users online

Code:

IP: {$v.session_ip}


Hi Mike

Is it just me or is anyone else gettng a "(104) Connection reset by peer" when trying to access dnsstuff? Anyone else have an alternative?

ramcity 04-09-2006 01:21 PM

How about if a lookup was done on the GeoIP country database, and perhaps even the GeoLiteCity database, to show the country and suburb the visitor hails from?

Perhaps it's not a feature that users may want to see (a bit like "big brother"), but might be handy in the admin side of things. Both these databases are freely available from http://www.maxmind.com/app/ip_locate

Rod

thundernugs 04-09-2006 03:54 PM

cliff, i've been using this href


in stats.tpl and it has never given an error

i'm sure you can use whatever dns lookup site you want, just test it to figure out what the url is that calls the information and insert it in stats.tpl

TA 05-14-2006 05:12 PM

Has anybody had any luck coding this into 4.0.18?

TA 05-16-2006 12:14 PM

I installed this per the instructions in the 1st post. Works as advertised in 4.0.18. Thank you!

Paul H 08-29-2006 11:37 AM

Re: IP Addresses in Users Online for all users
 
I have version 4 0 15 and it doesn't seem to work ie no IP address showing.
I would think if it works for version 14 ,17 and 18 then 15 would be fine.


Ignore the above it does work for me !

denlem 10-22-2006 04:17 PM

Re: IP Addresses in Users Online for all users
 
Does anyone have this working in 4.1.3?

I have tried but can't seem to get it to work.

laurieblake 02-08-2007 01:57 AM

Re: IP Addresses in Users Online for all users
 
Quote:

Originally Posted by denlem
Does anyone have this working in 4.1.3?

I have tried but can't seem to get it to work.


Nor can I in 4.1.5. If someone has it working it would be great if you could compliment the original good-hearted post and post the full code.

Cheers

laurieblake 02-21-2007 12:01 PM

Re: IP Addresses in Users Online for all users
 
Quote:

Originally Posted by laurieblake
Nor can I in 4.1.5. If someone has it working it would be great if you could compliment the original good-hearted post and post the full code.

Cheers


Just to explain, in the "Users Online" Statistics screen under customer i see Unregistered customer IP: and no IP address. Any ideas?

laurieblake

snowman99 03-09-2007 11:18 AM

Re: IP Addresses in Users Online for all users
 
Hi,
I just implemented this on 4.1.3 with no problem. I entered the code exactly as specified.

Try replacing the session_ip variable with a literal string in the auth.php file.
$session_ip = "1.2.3.4"; This is just to make sure the rest of the code works in the other two files. If it works then you know the problem is in the auth.php code. If it doesn't you know it's further down in either the stats.php or stats.tpl code.

laurieblake 03-09-2007 03:46 PM

Re: IP Addresses in Users Online for all users
 
Thanks snowman99. I am looking at your suggestion. The biggest problem that i seem to have with x-cart is that I chose to add Crystal Blue Skins. It completely changes x-cart's command syntax and variables. Programs, add-ons, mods etc that work for everyone else just does not work for us. I like the look but hate the consequences.

I'll post my findings.

Cheers.

carpeperdiem 03-22-2007 07:26 AM

Re: IP Addresses in Users Online for all users
 
Works great in 4.1.6 - altough there are some very minor code changes -- it's very easy to figure it out... don't replace the entire block of code, just find the differences and use the 1 or 2 new lines.

Also, if you want to make the IP clickable, use this code instead of "IP:{$v.session_ip}"

Code:

&nbsp;IP: <a href="http://www.dnsstuff.com/tools/whois.ch?ip={$v.session_ip}&cache=off" target="_blank">{$v.session_ip}</a>

herbj 03-22-2007 11:19 AM

Re: IP Addresses in Users Online for all users
 
I have this working in 4.0.19. The only thing I do not understand is that I have 2 entries for each visitor.
1 shows the IP and the other does not.

Any Suggestions.

Oh. This originally did not work for me but then I realized I had missed a piece of code that belongs in the "auth.php" file. (in red) Hope this helps...

[code}
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');
}
[/code}

josebueso 03-23-2007 10:56 AM

Re: IP Addresses in Users Online for all users
 
Quote:

Originally Posted by carpeperdiem
Works great in 4.1.6 - altough there are some very minor code changes -- it's very easy to figure it out... don't replace the entire block of code, just find the differences and use the 1 or 2 new lines.

Also, if you want to make the IP clickable, use this code instead of "IP:{$v.session_ip}"

Code:

&nbsp;IP: <a href="http://www.dnsstuff.com/tools/whois.ch?ip={$v.session_ip}&cache=off" target="_blank">{$v.session_ip}</a>


I used this code without any issue but I wanted to add the the code to make it clickable it worked for some time than I get page not found error. Was my IP banned after a few test clicks? or is their site is down? ( This program cannot display the webpage

Most likely causes:
You are not connected to the Internet.
The website is encountering problems.
There might be a typing error in the address.

What you can try:
Check your Internet connection. Try visiting another website to make sure you are connected)

Any help please

Jose

sindifizer 03-25-2007 02:12 PM

Re: IP Addresses in Users Online for all users
 
all i can say is wow

thanks a ton, this was something i have been dreaming about

now all i have to do is figure out where exactly to insert the code that allows you to click to do a locate ip

again, thanks. love it.

herbj 03-26-2007 09:01 AM

Re: IP Addresses in Users Online for all users
 
Quote:

Originally Posted by sindifizer
all i can say is wow

thanks a ton, this was something i have been dreaming about

now all i have to do is figure out where exactly to insert the code that allows you to click to do a locate ip

again, thanks. love it.



Use this code:
Code:

&nbsp;IP: <a href="http://www.dnsstuff.com/tools/whois.ch?ip={$v.session_ip}&cache=off" target="_blank">{$v.session_ip}</a>

Code goes in"skin1>modules>Users_online>stats.tpl" and replaces
Code:

"IP:{$v.session_ip}"

At least that is what worked for me!

Save your files before changing any code!

Good Luck!

herbj 03-28-2007 01:24 PM

Re: IP Addresses in Users Online for all users
 
Quote:

Originally Posted by herbj
I have this working in 4.0.19. The only thing I do not understand is that I have 2 entries for each visitor.
1 shows the IP and the other does not.



I figured this out and corrected it.

Works Great!

robertswww 03-28-2007 01:41 PM

Re: IP Addresses in Users Online for all users
 
Hi Herbj,

Glad to hear you figured the code out for X-cart 4.0.19 and fixed your duplicate entries problem.

If you could post your final, revised code, that would be great!

Thanks,

Robert


All times are GMT -8. The time now is 01:30 AM.

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