![]() |
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 |
Re: Seeing $_SERVER variables in home.php
Try the $HTTP_SERVER_VARS variable.
|
Re: Seeing $_SERVER variables in home.php
Quote:
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? |
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. |
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 |
Re: Seeing $_SERVER variables in home.php
Try this:
Code:
x_session_register("referer_session"); |
Re: Seeing $_SERVER variables in home.php
Quote:
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 |
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 -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.