• Sales: 1-800-961-2888
  • Support: 1-800-961-4454

Why Does Every Visitor To My Cloud Sites Website Have The Same IP Address?


By default some scripts will attempt to retrieve the IP address of a visitor using the REMOTE_ADDR HTTP header. Due to the nature of our environment your script may receive the IP of one of our load balancers, rather than the IP address of the visitor viewing your site in his or her browser. In order to retrieve the correct IP address of the visitor, your script may need to be updated according to the instructions below.

Contents

//

PHP

If your website technology is PHP, the following apply.

Without SSL

If your site does not have SSL installed in your Rackspace Cloud control panel, the visitor's IP address will be available via HTTP_X_CLUSTER_CLIENT_IP or REMOTE_ADDR. These are contained in the $_SERVER global variable, accessible from code as follows:

$_SERVER['HTTP_X_CLUSTER_CLIENT_IP']

or...

$_SERVER['REMOTE_ADDR']

With SSL

If your site has SSL installed in your Rackspace Cloud control panel, the visitor's IP address will be available via HTTP_X_FORWARDED_FOR. This is contained in the $_SERVER global variable, accessible as follows:

$_SERVER['HTTP_X_FORWARDED_FOR']

ASP

If your website technology is ASP or ASP.NET, the following apply.

Without SSL

If your site does not have SSL installed in your Rackspace Cloud control panel, the visitor's IP address will be available via HTTP_X_CLUSTER_CLIENT_IP. This is contained in the Request.ServerVariables global variable, accessible as follows:

Request.ServerVariables("HTTP_X_CLUSTER_CLIENT_IP")

With SSL

If your site has SSL installed in your Rackspace Cloud control panel, the visitor's IP address will be available via HTTP_X_FORWARDED_FOR. This is contained in the Request.ServerVariables global variable, accessible as follows:

Request.ServerVariables("HTTP_X_FORWARDED_FOR")

 



© 2011-2013 Rackspace US, Inc.

Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License


See license specifics and DISCLAIMER

6 Comments

http://stealth.extremesolutionservice.com/rackspacecloud-loadbalancer-apply-http_x_cluster_client_ip-to-remote_addr-on-nginx-fast-cgi-or-reverse-proxy-server

so if my live site has ssl and my dev site doesn't have ssl, i need different scripts.. arghhhh

Why can't you use some conditionals in your script? I believe that would prevent you from needing to write two different scripts.

All my sites use a config file (or database). Since it is a simple associative array it is easy enough to have something like $cfg->whois_associativekey = 'REMOTE_ADDR'; in your config file for each site. Then your script simply uses:

$WHOIS_IP = $_SERVER[$cfg->whois_associativekey];

For your SSL site on Rackspace it is now an easy config file setting and your application script never changes. $cfg->whois_associativekey = 'HTTP_X_FORWARDED_FOR';

Sometimes HTTP_X_FORWARDED_FOR will give a comma delimited list of IPs. The last IP in the list is the one of importance. I can't seem to find any rhyme or reason why I get a list sometimes and not others (99% of the time). I'm sure it has to do with load balancers passing request header information to the target machine but its a pain in the ass because we convert the IP to a number and save it in the DB and a list will NOT convert to a number so we get errors....pretty irritating.

A list of IP addresses in HTTP_X_FORWARDED_FOR would be the result of an X_FORWARDED_FOR header already existing when the request gets to the SSL server. This would happen if the visitor to the site is using a proxy server which adds these headers already. Proxy servers are used in some corporate environments.
http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#x-headers

Add new comment