X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Seeing $_SERVER variables in home.php (https://forum.x-cart.com/showthread.php?t=35697)

gkeraunen 11-25-2007 08:34 PM

Seeing $_SERVER variables in home.php
 
I successfully include the following in via home.tpl in home.php:

print $_SERVER['REFERER'];
print $_SERVER['REQUEST_URI'];
print $_SERVER['REMOTE_ADDR'];
print "hello!!\n<br>";

But this only prints "hello!!" and does not print the $_SERVER variables.

This is in 4.0.13, but I think it applies to all versions?
Can you point me in the right direction?

Thanks,

-Michael

Ene 11-25-2007 09:58 PM

Re: Seeing $_SERVER variables in home.php
 
Try the $HTTP_SERVER_VARS variable.

gkeraunen 11-26-2007 06:01 AM

Re: Seeing $_SERVER variables in home.php
 
Quote:

Originally Posted by Ene
Try the $HTTP_SERVER_VARS variable.


Thanks Ene, but it didn't work. I tried

print $HTTP_SERVER_VARS["REMOTE_ADDR"];
print $HTTP_SERVER_VARS["HTTP_REFERER"];
print $HTTP_SERVER_VARS["HTTP_USER_AGENT"];
print "hello again\n<br>";


and still got... "hello again"

Is X-cart doing something strange here?

geckoday 11-27-2007 06:34 AM

Re: Seeing $_SERVER variables in home.php
 
X-Cart definitely does something strange for HTTP_REFERER and stuffs it into $HTTP_REFERER then unsetting $HTTP_SERVER_VARS["HTTP_REFERER"]. This is done in prepare.php and checks to see if its loaded in an iframe and uses iframe_referer instead of HTTP_REFERER if so. REMOTE_ADDR is stuffed into $REMOTE_ADDR. Its also stuffed into $CLIENT_IP if not accessed through a proxy and tries to get the real client IP if accessed through a proxy. X-Cart also stuffs all of the elements of $HTTP_SERVER_VARS into individual variables with the same name as the element key (e.g. $HTTP_SERVER_VARS['HTTP_USER_AGENT'] is stuffed into $HTTP_USER_AGENT). You can use either (except yout must use $HTTP_REFERER) but using the individual variables will give you the advantage of any special logic X-Cart applies as in the above variables.

But your real problem is probably not declaring $HTTP_SERVER_VARS as global. Try adding this before your print statements.

global $HTTP_SERVER_VARS;

Or use the individual variable names if you want to use them.

gkeraunen 11-27-2007 08:03 AM

Re: Seeing $_SERVER variables in home.php
 
Declaring it global did the trick (in both cases). Thank you Ralph!

It seems that by the time my code snippet is loaded (via home.tpl) the referrer is always my own domain. I'm trying to capture the 'original' referrer (search engine, affiliate, etc) on the first entry page entry and, ideally, make it available as a session variable throughout the system. Any tricks that you know of to achieve this?

-Michael

geckoday 11-28-2007 06:25 AM

Re: Seeing $_SERVER variables in home.php
 
Try this:

Code:

x_session_register("referer_session");
global $referer_session;
print $referer_session;


gkeraunen 11-28-2007 07:10 AM

Re: Seeing $_SERVER variables in home.php
 
Quote:

Originally Posted by geckoday
Try this:

Code:

x_session_register("referer_session");
global $referer_session;
print $referer_session;




Ahhh. You just beat me to it!!! :) Thanks.

I ended up using the cookie set in referer.php:

$HTTP_COOKIE_VARS["RefererCookie"];

Now to figure how to get the original REQUEST. I'll post later.

-Michael

gkeraunen 11-29-2007 01:45 PM

Re: Seeing $_SERVER variables in home.php
 
OK, to use access the original Request URI via a cookie, I modified referer.php by adding the following code at the end. It worked for my 4.0.13 edition. Hope it helps someone.

Code:

# set a cookie that remembers the original request  Added by Michael on 11-28-07

        $request = $HTTP_SERVER_VARS["REQUEST_URI"];
x_session_register("request_session");
if (!isset($HTTP_COOKIE_VARS["RequestCookie"]) || empty($request_session)) {
        if(empty($request_session)) {
                $referer_session = (isset($HTTP_COOKIE_VARS["RequestCookie"])?$HTTP_COOKIE_VARS["RequestCookie"]:$request);
        }
        $request = $request_session;
        $_tmp = parse_url($current_location);
        setcookie("RequestCookie", $referer, time()+20*60, "/", $_tmp["host"]);
}


-Michael


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

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