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)

MythNReality 07-11-2013 03:13 PM

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

Originally Posted by elmirage001
For 4.5.5 (not tested in other versions)

I used the Smarty function {$smarty.server.REMOTE_ADDR} so I don't need to make any changes to postauth.php or stats.php anymore.

In store/skin/common_files/modules/Users_online/stats.tpl

Change From:
To:

Works with V4.6.0!

hoosierglass 12-14-2013 02:25 PM

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

Originally Posted by elmirage001
For 4.5.5 (not tested in other versions)

I used the Smarty function {$smarty.server.REMOTE_ADDR} so I don't need to make any changes to postauth.php or stats.php anymore.

In store/skin/common_files/modules/Users_online/stats.tpl

Change From:
To:


I have the same issue that it shows my IP address and not that of the person or machine browsing. Does anyone have and thoughts of work arounds for this?

elmirage001 12-15-2013 12:24 PM

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

Originally Posted by hoosierglass
I have the same issue that it shows my IP address and not that of the person or machine browsing. Does anyone have and thoughts of work arounds for this?


Works fine on my live 4.45 site but on my 4.6.0 dev site I have the same problem of all IPs showing as mine. It's on my list to look at before I go live with 4.6.x but it will most likely be a couple of months.

Mish 12-19-2013 11:20 PM

Re: IP Addresses in Users Online for all users
 
Hi everyone - you may want to check out this thread on making the Users Online table sortable and look good

hoosierglass 12-20-2013 06:57 AM

Re: IP Addresses in Users Online for all users
 
So has anyone been able to figure out why {$smarty.server.REMOTE_ADDR} shows your IP and not that of the people browsing the site?

qualiteam 12-22-2013 10:18 PM

Re: IP Addresses in Users Online for all users
 
{$smarty.server.REMOTE_ADDR} shows IP of the user viewing the template. Since you are the user viewing the page (and template), it displays yours IP.

So, instead of retrieving the address when the template is rendered, you should collect it in a php script and store in the user's session (so every user will have its IP in his session data). And, when displaying the template listing online users, show addresses stored in users' sessions.

Unfortunately, I can't post code that will work for all XC versions, but the logic will be as I've described.

elmirage001 12-22-2013 11:31 PM

Re: IP Addresses in Users Online for all users
 
Hi Alex,
Thank you for the information. Can you let us know why it worked in 4.4.5?
Thank you! Paul

anandat 12-23-2013 06:21 AM

Re: IP Addresses in Users Online for all users
 
Everyone wants this small feature in admin so I request QT that it should be added by default since it's very small but useful feature.
Infact I have got more custom coded by using country IP detection functionality of module multi currency module & now I can see visitor's country also next to the IP address.

qualiteam 12-24-2013 02:13 AM

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

Originally Posted by elmirage001
Thank you for the information. Can you let us know why it worked in 4.4.5?


Black magic, I guess :-)

Using {$smarty.server.REMOTE_ADDR} in the template listing online users will display your IP address for each user in the list, not IPs of these users. However, code from earlier posts in this thread should work - I see it stores REMOTE_ADDR in the user session.

Quote:

Originally Posted by anandat
Everyone wants this small feature in admin so I request QT that it should be added by default since it's very small but useful feature.



I've added your request to the wish list, but can't say when developers can start working on it - there is a lot of work in the list.

elmirage001 12-27-2013 10:26 AM

Re: IP Addresses in Users Online for all users
 
I have it working now in 4.6.1 using an edited version of post 105 by Mish and the edit done by denlem in 106. Below is the code that I'm using.

In postauth.php
PHP 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'] : "");

    
$current_date XC_TIME;

    if (empty(
$session_create_date)) {
        
$session_create_date $current_date;
    }

    
$session_ip getenv('REMOTE_ADDR');



In modules/Users_online/stats.php
PHP Code:

$rec['session_create_date'] = $data['session_create_date'] + $config["Appearance"]["timezone_offset"];
    
    
//if (!empty($data['session_ip']))
    //{
    //    if ($HTTP_SERVER_VARS['REMOTE_ADDR'] != $data['session_ip'])
    //       $rec['session_ip'] = gethostbyaddr($data['session_ip']);
    //    else
    //       $rec['session_ip'] = "Admin";
    // }
    // else
     
     
$rec['session_ip'] = $data['session_ip'];
    
    
$statistics[] = $rec


In skin/common_files/modules/Users_online/stats.tpl (denlem edit)
Replace
Code:

  <td bgcolor="#FFFFFF" nowrap="nowrap" valign="top">{if $v.userinfo ne ''}<a href="{$catalogs.admin}/user_modify.php?user={$v.userinfo.id}&amp;usertype=C">{$v.userinfo.firstname} {$v.userinfo.lastname}</a>{if $v.userinfo.status eq 'A'}<br /><i>({$lng.lbl_anonymous_customer})</i>{/if}{else}{$lng.lbl_unregistered_customer}{/if}</td>

With
Code:

<td bgcolor="#FFFFFF" nowrap="nowrap" valign="top">{if $v.userinfo ne ''}<a href="{$catalogs.admin}/user_modify.php?user={$v.userinfo.id}&usertype=C">{$v.userinfo.firstname} {$v.userinfo.lastname}</a>{if $v.userinfo.status eq 'A'}<br /><i>({$lng.lbl_anonymous_customer})</i>{/if}{else}{$lng.lbl_unregistered_customer}{/if}</br>IP: <a href="http://cqcounter.com/whois/?query={$v.session_ip}" target="_blank">{$v.session_ip}</a>  </td>

The only change I made was to comment out some of the added PHP code in stats.php. With that change it's working fine for me. Somebody else can play with the other PHP code if they want.


All times are GMT -8. The time now is 10:20 AM.

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