note 19937 deleted from language.variables.predefined by nlopess

From: Date: Tue, 13 Jan 2004 14:52:47 +0000
Subject: note 19937 deleted from language.variables.predefined by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-63437@lists.php.net to get a copy of this message
Note Submitter: destes@ix.netcom.com.nospam ---- Further complicating the debate about getting someone's IP, I should note that getenv() doesn't exist in ISAPI mode. However, the $_SERVER array exists even in ISAPI mode if PHP is 4.1.0 or over. So, in order to accomodate ISAPI mode, you can get IPs like this: function getip() { if ($_SERVER) { if ( $_SERVER[HTTP_X_FORWARDED_FOR] ) { $realip = $_SERVER["HTTP_X_FORWARDED_FOR"]; } elseif ( $_SERVER["HTTP_CLIENT_IP"] ) { $realip = $_SERVER["HTTP_CLIENT_IP"]; } else { $realip = $_SERVER["REMOTE_ADDR"]; } } else { if ( getenv( 'HTTP_X_FORWARDED_FOR' ) ) { $realip = getenv( 'HTTP_X_FORWARDED_FOR' ); } elseif ( getenv( 'HTTP_CLIENT_IP' ) ) { $realip = getenv( 'HTTP_CLIENT_IP' ); } else { $realip = getenv( 'REMOTE_ADDR' ); } } return $realip; } If you're running ISAPI mode below PHP 4.1.0, you'd have to modify this to use the array $HTTP_SERVER_VARS, but those cases will be few indeed.

« previous php.notes (#63437) next »