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)
-   -   Display Customer IP during checkout (https://forum.x-cart.com/showthread.php?t=12693)

hooter 03-09-2005 06:31 AM

Display Customer IP during checkout
 
First, my apologies if this has been addressed elsewhere - I've searched and seen the posts regarding capturing the IP address for back-end purposes but hadn't seen anything quite exactly like this.

Also this may seem a bit pretentious to post in Custom Mods, (it's just a simple hack) so moderators please feel free to move to more appropriate forum.

It is also a good example/excercise of how you can use your own "pseudo" variables in any of your language variables.

Say for instance, you would like to display to a customer during checkout that their IP address is part of your anti-fraud technology - please, let's skip the debate as to whether this is useful or not; some clients want this based on the high-risk markets they are in and feel it is at least a minor deterrent. :wink:

Okay, first create a new text label:
Administration -> Languages -> Select Language -> Select Topic -> Text
For variable put: msg_customer_IP
For Description put: Customer IP address
For Value use something like this (note the double curly brackets around the word customer_ip:
Code:

<font color=red>*NOTE*</font> Your IP address : {{customer_ip}} is tracked during the checkout process as part of our anti-fraud technology.

Then to display this information wherever you want, use:
Code:

{$lng.msg_customer_ip|substitute:"customer_ip":$smarty.server.REMOTE_ADDR}
I added this as the last line of skin1/customer/main/cart_totals.tpl thereby displaying during every step of the checkout process.

The "substitute" pipe replaces your pseudo variable "customer_ip" with the smarty global containing the remote IP address.

Credits go to PhilJ for putting me on to the smarty global thing:
http://forum.x-cart.com/viewtopic.php?t=14490&highlight=remoteaddr

I was trying to use a PHP global and couldn't get it to work quite right. Thanks Phil 8)

x-online 03-09-2005 05:23 PM

isn't this IP already intergrated with latest version?
if you go to order and click on whatever order you wanted you wil lsee
just under status: and tracking number:
IP address:
xxx.xxx.xxx.xxx

hooter 03-09-2005 05:56 PM

x-online,

Please read my post and its purpose carefully - this is for display to customer during checkout :wink:

x-online 03-09-2005 07:23 PM

Sorry for my misreading ^_^''

Nice work!

simitpatel 02-07-2006 07:34 AM

small change
 
i just implemented this and had to make one small change. the code:
Code:

{$lng.msg_customer_ip|substitute:"customer_ip":$smarty.server.REMOTE_ADDR}

should be:
Code:

{$lng.msg_customer_IP|substitute:"customer_ip":$smarty.server.REMOTE_ADDR}

B00MER 02-07-2006 09:04 AM

I don't think the default takes Proxies or IP's behind LAN's into consideration. Here's a function that can easily be used in config.php to grab the absolute IP of the user. Thanks to NuLime for the function.
Code:

function fetch_remote_address() {
        $_SERVER = $GLOBALS['HTTP_SERVER_VARS'];
        # Record basic remote address.
        $remote_address = $_SERVER['REMOTE_ADDR'];
        # Take proxies into consideration or IPs behind a LAN.
        if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR'] != 'unknown' && $_SERVER['HTTP_X_FORWARDED_FOR'] != $_SERVER['REMOTE_ADDR']) {
                $HXFF_temp = preg_replace('/, ?unknown/i','',$_SERVER['HTTP_X_FORWARDED_FOR']); // Remove any trailing 'unknowns'.
                $remote_address .= ','.$HXFF_temp;
        }
        if (isset($_SERVER['HTTP_CLIENT_IP']) && $_SERVER['HTTP_CLIENT_IP'] != 'unknown' && $_SERVER['HTTP_CLIENT_IP'] != $_SERVER['HTTP_X_FORWARDED_FOR'] && $_SERVER['HTTP_CLIENT_IP'] != $_SERVER['REMOTE_ADDR']) {
                $HCI_temp = preg_replace('/, ?unknown/i','',$_SERVER['HTTP_CLIENT_IP']); // Remove any trailing 'unknowns'.
                $remote_address .= ','.$HCI_temp;
        }
       
        return $remote_address;
}


anandat 03-21-2006 05:19 AM

Dear Boomer,
Where exactly to put this code in config.php ?

We need to just put this code & nothing else ? will it display the customer's original IP on chekout ?

B00MER 03-21-2006 06:45 AM

Quote:

Originally Posted by anandat
Dear Boomer,
Where exactly to put this code in config.php ?

We need to just put this code & nothing else ? will it display the customer's original IP on chekout ?


Place it towards the bottom of the file, before the WARNING comment.

Add this afterwards to call the IP anywhere:
Code:

$smarty->assign("customers_ip", fetch_remote_address());
And call the variable in any .tpl {$customers_ip}

jbart976 04-13-2006 07:01 PM

Place it towards the bottom of the file, before the WARNING comment.

Add this afterwards to call the IP anywhere:
Code:
$smarty->assign("customers_ip", fetch_remote_address());

And call the variable in any .tpl {$customers_ip}


Boomer, what do you mean by "And call the variable in any .tpl {$customers_ip}"

I copied the code into config like you said and added the line afterwards, but I'm still not seeing an IP.

Thanks.[/quote]

B00MER 04-13-2006 11:40 PM

Code:

die(fetch_remote_address());
Add this after the function decleration in config.php, if it doesn't output anything than the function may need to use other GLOBAL variables, i.e. $HTTP_GET vs $_GET, etc.


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

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