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

Seeing $_SERVER variables in home.php

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 11-25-2007, 08:34 PM
 
gkeraunen gkeraunen is offline
 

Advanced Member
  
Join Date: Jan 2004
Posts: 37
 

Default 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
__________________
X-Cart 4.1.9
PHP 4.4.1
MySQL 4.0.27
Linux
Apache
Reply With Quote
  #2  
Old 11-25-2007, 09:58 PM
  Ene's Avatar 
Ene Ene is offline
 

X-Cart team
  
Join Date: Aug 2004
Posts: 907
 

Default Re: Seeing $_SERVER variables in home.php

Try the $HTTP_SERVER_VARS variable.
__________________
Eugene Kaznacheev,
Evangelist/Product Manager at Ecwid: http://www.ecwid.com/ (since Sept 2009)

ex-Head of X-Cart Tech Support Department
ex- X-Cart Hosting Manager - X-Cart hosting
ex-X-Cart Technical Support Engineer


Note: For the official guaranteed tech support services please turn to the Customers HelpDesk.
Reply With Quote
  #3  
Old 11-26-2007, 06:01 AM
 
gkeraunen gkeraunen is offline
 

Advanced Member
  
Join Date: Jan 2004
Posts: 37
 

Default 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?
__________________
X-Cart 4.1.9
PHP 4.4.1
MySQL 4.0.27
Linux
Apache
Reply With Quote
  #4  
Old 11-27-2007, 06:34 AM
 
geckoday geckoday is offline
 

X-Wizard
  
Join Date: Aug 2005
Posts: 1,073
 

Default 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.
__________________
Manuka Bay Company
X-Cart Version 4.0.19 [Linux]

UGG Boots and other fine sheepskin products
http://www.snowriver.com
Reply With Quote
  #5  
Old 11-27-2007, 08:03 AM
 
gkeraunen gkeraunen is offline
 

Advanced Member
  
Join Date: Jan 2004
Posts: 37
 

Default 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
__________________
X-Cart 4.1.9
PHP 4.4.1
MySQL 4.0.27
Linux
Apache
Reply With Quote
  #6  
Old 11-28-2007, 06:25 AM
 
geckoday geckoday is offline
 

X-Wizard
  
Join Date: Aug 2005
Posts: 1,073
 

Default Re: Seeing $_SERVER variables in home.php

Try this:

Code:
x_session_register("referer_session"); global $referer_session; print $referer_session;
__________________
Manuka Bay Company
X-Cart Version 4.0.19 [Linux]

UGG Boots and other fine sheepskin products
http://www.snowriver.com
Reply With Quote
  #7  
Old 11-28-2007, 07:10 AM
 
gkeraunen gkeraunen is offline
 

Advanced Member
  
Join Date: Jan 2004
Posts: 37
 

Smile 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
__________________
X-Cart 4.1.9
PHP 4.4.1
MySQL 4.0.27
Linux
Apache
Reply With Quote
  #8  
Old 11-29-2007, 01:45 PM
 
gkeraunen gkeraunen is offline
 

Advanced Member
  
Join Date: Jan 2004
Posts: 37
 

Default 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
__________________
X-Cart 4.1.9
PHP 4.4.1
MySQL 4.0.27
Linux
Apache
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 07:43 AM.

   

 
X-Cart forums © 2001-2020