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

IP In Admin Users Online for 4.3

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 03-17-2010, 02:26 PM
  hoosierglass's Avatar 
hoosierglass hoosierglass is offline
 

X-Adept
  
Join Date: Aug 2006
Location: Zionsville, IN
Posts: 974
 

Default IP In Admin Users Online for 4.3

I played around today and got this to work for me the same way it did in 4.1.12.

THIS CODE IS FOR 4.3.X

in postauth.php below
if (!defined('HTTPS_CHECK_SKIP')) {
@include $xcart_dir.DIR_CUSTOMER."/https.php";
}

change:
PHP 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();


to:
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']:"");
if (empty(
$session_create_date))
$session_create_date time();
$current_date time();
$session_ip getenv('REMOTE_ADDR');


In modules/Users_online/stats.php below:
$rec['session_create_date'] = $data['session_create_date']+$config["Appearance"]["timezone_offset"];

insert:
PHP Code:
$rec['session_ip'] = $data['session_ip']; 

In skin1/modules/Users_online/stats.tpl
change:
PHP Code:
<td bgcolor="#FFFFFF" nowrap="nowrap" valign="top">{if $v.userinfo ne ''}<a href="user_modify.php?user={$v.userinfo.login|escape:"url"}&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

to:
PHP Code:
<td bgcolor="#FFFFFF" nowrap="nowrap" valign="top">{if $v.userinfo ne ''}<a href="user_modify.php?user={$v.userinfo.login|escape:"url"}&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://private.dnsstuff.com/tools/whois.ch?ip={$v.session_ip}&cache=on" target="_blank">{$v.session_ip}</a></td

IPs will not appear until someone goes onto your website after you change the above codes.
__________________
X-Cart Gold 4.7.7
Custom Work from www.luminointernet.com
www.indy-pen-dance.com
Reply With Quote

The following 2 users thank hoosierglass for this useful post:
neonrider (08-15-2017), New York (06-25-2014)
  #2  
Old 03-17-2010, 02:45 PM
 
balinor balinor is offline
 

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

Default Re: IP In Admin Users Online for 4.3

Moving to Completed Custom Mods
__________________
Padraic Ryan
Ryan Design Studio
Professional E-Commerce Development
Reply With Quote
  #3  
Old 03-17-2010, 03:07 PM
 
Pyro Pyro is offline
 

X-Adept
  
Join Date: Nov 2009
Posts: 506
 

Default Re: IP In Admin Users Online for 4.3

Great work! I'll be using it for sure.
__________________
Best Wishes,
James

4.5.2 Gold (work in progress)
Reply With Quote
  #4  
Old 03-21-2010, 07:55 AM
 
bionicfish bionicfish is offline
 

Member
  
Join Date: Jun 2006
Posts: 10
 

Default Re: IP In Admin Users Online for 4.3

Thanks works well. Am tempted to actually link this code to another look-up and actually geo-locate the ip address and then pull back the country name and display that instead of the ip address, shouldnt be that tough...
__________________
Xcart 4.3.1
Reply With Quote
  #5  
Old 03-21-2010, 07:56 AM
 
Pyro Pyro is offline
 

X-Adept
  
Join Date: Nov 2009
Posts: 506
 

Default Re: IP In Admin Users Online for 4.3

bionicfish: If you do, be sure to share!
__________________
Best Wishes,
James

4.5.2 Gold (work in progress)
Reply With Quote
  #6  
Old 04-16-2010, 06:53 AM
 
lilypad lilypad is offline
 

Advanced Member
  
Join Date: Apr 2007
Posts: 40
 

Default Re: IP In Admin Users Online for 4.3

silly ? but would this be the same in 4.2.2?
__________________
Version 4.7.4
Using reBOOT theme
www.the-lilypad.com
Reply With Quote
  #7  
Old 04-16-2010, 07:04 AM
  hoosierglass's Avatar 
hoosierglass hoosierglass is offline
 

X-Adept
  
Join Date: Aug 2006
Location: Zionsville, IN
Posts: 974
 

Default Re: IP In Admin Users Online for 4.3

You should have no problem in 4.2 as I used that as a template to get this to work.

Mike
__________________
X-Cart Gold 4.7.7
Custom Work from www.luminointernet.com
www.indy-pen-dance.com
Reply With Quote
  #8  
Old 04-16-2010, 12:00 PM
 
lilypad lilypad is offline
 

Advanced Member
  
Join Date: Apr 2007
Posts: 40
 

Default Re: IP In Admin Users Online for 4.3

where exactly in admin will this show up? will be super helpful to get this working, if i can!

this is what i show in postauth.php below
if (!defined('HTTPS_CHECK_SKIP')) {
@include $xcart_dir.DIR_CUSTOMER."/https.php";
}

Quote:
if (!empty($active_modules['Users_online']) || !empty($active_modules["Greet_Visitor"])) {
x_session_register("session_create_date");
if (empty($session_create_date))
$session_create_date = time();
}

if (!empty($active_modules['Users_online'])) {
x_session_register("current_url_page");
x_session_register("current_date");
$current_url_page = $php_url['url'].($php_url['query_string']?"?".$php_url['query_string']:"");

$current_date = time();
}

so, would the replacement be the same or would it be a bit different??

thanks.
__________________
Version 4.7.4
Using reBOOT theme
www.the-lilypad.com
Reply With Quote
  #9  
Old 04-16-2010, 12:04 PM
  hoosierglass's Avatar 
hoosierglass hoosierglass is offline
 

X-Adept
  
Join Date: Aug 2006
Location: Zionsville, IN
Posts: 974
 

Default Re: IP In Admin Users Online for 4.3

I don't see a problem with switching this out but to err on the side of caution make a back up of your original postauth.php file.

The will show up in stats/users online in the admin menu.
__________________
X-Cart Gold 4.7.7
Custom Work from www.luminointernet.com
www.indy-pen-dance.com
Reply With Quote
  #10  
Old 08-03-2010, 09:23 PM
 
Torres Torres is offline
 

Member
  
Join Date: Apr 2010
Posts: 26
 

Default Re: IP In Admin Users Online for 4.3

Quote:
Originally Posted by bionicfish
Thanks works well. Am tempted to actually link this code to another look-up and actually geo-locate the ip address and then pull back the country name and display that instead of the ip address, shouldnt be that tough...

I have mine working with a local table, but there are several services that let you pull from their geo location database for free.

This is a simple one that I used, working in 4.3.2. Note that the source server adds a small delay to limit requests (unless you donate to them). Please backup your two files first in case you find the delay too long on your site. It took about 8 seconds to run "Users Online" for me, worthwhile to me, but my site might not be as large as most.

Also, if someone wanted to change this code to keep each visitor's ip info in a cookie, this should reduce any delay to nothing.

NOTE: These changes assume that you've already added the "session_ip" changes mentioned in this thread.


In \modules\Users_online\stats.php, below:
$rec['session_ip'] = $data['session_ip'];

insert:

PHP Code:
/***** BEGIN Hack: Show IP Info in Users Online stats *****/
  
$key recursiveArraySearch($statistics$data['session_ip'], 'session_ip');
  if (
$key) {
    
$rec['country'] = $statistics[$key]['country'];
    
$rec['region'] = $statistics[$key]['region'];
    
$rec['city'] = $statistics[$key]['city'];
    
$rec['flag'] = $statistics[$key]['flag'];
  } else {
    
$ipDetail countryCityFromIP$data['session_ip'] );
    
$rec['country'] = $ipDetail['country'];
    
$rec['region'] = $ipDetail['region'];
    
$rec['city'] = $ipDetail['city'];
    
$rec['flag'] = $ipDetail['flag'];
  
/***** END Hack ***********************************/ 


At the end of the same file, just before the closing:
?>

insert:

PHP Code:
/***** BEGIN Hack: Show IP Info in Users Online stats *****/
#
# This function searches a multi-dimensional array for a given key and returns it's value.
#
function recursiveArraySearch($haystack$needle$index null)
{
  
$aIt = new RecursiveArrayIterator($haystack);
  
$it  = new RecursiveIteratorIterator($aIt);
   
  while(
$it->valid())
  {       
    if (((isset(
$index) and ($it->key() == $index)) or (!isset($index))) and ($it->current() == $needle)) {
      return 
$aIt->key();
    }
    
$it->next();
  }
   
  return 
false;
}


#
# This function returns the country, region and city for a given ip address.
# Developed by Roshan Bhattarai [url]http://roshanbh.com.np[/url]
#
function countryCityFromIP($ipAddr)
{
  
// verify the IP address for the
  
ip2long($ipAddr)== -|| ip2long($ipAddr) === false trigger_error("Invalid IP"E_USER_ERROR) : "";
  
$ipDetail=array(); //initialize a blank array

  // get the XML result from hostip.info
  
$xml file_get_contents("http://ipinfodb.com/ip_query.php?ip=".$ipAddr."&timezone=false");

  
// get the country name from inside the node <CountryName> and </CountryName>
  
preg_match("@<CountryName>(.*?)</CountryName>@si",$xml,$match_country);

  
// assign the country name to the $ipDetail array
  
$ipDetail['country']=$match_country[1];
  
  
// assign the country flag filename to the $ipDetail array
  
$ipDetail['flag']=str_replace(" ","_",strtolower($match_country[1]));
  
  
// get the state/province name from inside the node <RegionName> and </RegionName>
  
preg_match("@<RegionName>(.*?)</RegionName>@si",$xml,$match_region);
  
$ipDetail['region']=$match_region[1];
  
  
// get the city name from inside the node <gml:name> and </gml:name>
  
preg_match("@<City>(.*?)</City>@si",$xml,$match_city);

  
// assing the city name to the array
  
$ipDetail['city']=$match_city[1];

  
// return the array containing city, country and country code
  
return $ipDetail;
}
  
/***** END Hack ***********************************/ 


In \skin1\modules\Users_online\stats.tpl, change:

PHP Code:
<td bgcolor="#FFFFFF" nowrap="nowrap" valign="top">{if $v.userinfo ne ''}<a href="user_modify.php?user={$v.userinfo.login|escape:"url"}&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://private.dnsstuff.com/tools/whois.ch?ip={$v.session_ip}&cache=on" target="_blank">{$v.session_ip}</a></td>






to this:

PHP Code:
<td bgcolor="#FFFFFF" nowrap="nowrap" valign="top">
    {if 
$v.userinfo ne ''}
      <
b><a href="user_modify.php?user={$v.userinfo.login|escape:"url"}&usertype=C">{$v.userinfo.firstname} {$v.userinfo.lastname}</a></b>
      {if 
$v.userinfo.status eq 'A'}
        <
br /><i>({$lng.lbl_anonymous_customer})</i>
      {/if}
      <
br />
    {/if}
IP: <a href="http://private.dnsstuff.com/tools/whois.ch?ip={$v.session_ip}&cache=on" target="_blank">{$v.session_ip}</a><br />
    <
img src="/skin1/images/flags/flag_{$v.flag}.png" title="{$v.country}alt="" />
    <
span title="{$v.city}{$v.region}{$v.country}">{$v.city}</span>
  </
td

That's it.

The end result is you'll have the IP Address, a picture of the vistor's country flag and their city. Hovering the mouse shows their state/province and country name.

NOTE: I've removed the {$lng.lbl_unregistered_customer} label. You may prefer to add it back if you find it useful.

NOTE: You'll need to change the <img> path above to reflect where your flag images files are located. If I can figure out how to upload my flag files, I'll gladly do that. They are 16 pixel wide flag image files.
__________________
X-Cart 4.3.2
X-SpecialOffers
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



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 06:05 AM.

   

 
X-Cart forums © 2001-2020