[Typo3-dev] client IP
Michael Stucki
michael at typo3.org
Tue Nov 23 17:24:20 CET 2004
Reply to my own mail.
> BTW, I am not sure but I thought that getenv('REMOTE_ADDR') will return
> the same value like $_SERVER['REMOTE_ADDR'], so why does this function
> differ between them?
Obviously you can modify the value of $_SERVER['REMOTE_ADDR'] but can't
change the environment variable (putenv doesn't work).
So if you want to find out the IP of a client behind a proxy, you could add
these lines on top of your localconf.php:
--- cut ---
if(isset($_SERVER['HTTP_X_FORWARDED_FOR']) || isset($_SERVER['HTTP_CLIENT_IP'])) {
// Check if HTTP_X_FORWARDED_FOR or (altenatively) HTTP_CLIENT_IP only contains allowed chars (in other words: it's not a list)
if(ereg('^[0-9\.]+$',$_SERVER['HTTP_X_FORWARDED_FOR'])) $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_FORWARDED_FOR'];
elseif(ereg('^[0-9\.]+$',$_SERVER['HTTP_CLIENT_IP'])) $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_CLIENT_IP'];
}
--- cut ---
This requires that the REMOTE_ADDR is always queried using the $_SERVER
global. getenv('REMOTE_ADDR') will not work!
(Fortunately, TYPO3 consequently uses the first option, so this should not
be a problem...)
I'm gonna try this soon since we have exactly such a situation in our
company...
- michael
--
Want support? Please read the list rules first: http://typo3.org/1438.0.html
More information about the TYPO3-dev
mailing list