class MyClass {
/**
* @access public
* @variables
*/
var $ipAddress, $proxyAddress = '';
function setIPAddress() {
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
if (isset($_SERVER['HTTP_CLIENT_IP'])) { $this->proxyAddress = $_SERVER['HTTP_CLIENT_IP']; }
else { $this->proxyAddress = $_SERVER['REMOTE_ADDR']; }
$this->ipAddress = $_SERVER['HTTP_X_FORWARDED_FOR']; }
elseif (isset($_SERVER['HTTP_CLIENT_IP'])) { $this->ipAddress = $_SERVER['HTTP_CLIENT_IP']; }
else { $this->ipAddress = $_SERVER['REMOTE_ADDR']; }
}
}and whenever you want to show the ip address you just do:
$MyClass = new MyClass();
and you can call the function once like $Myclass->setIPAddress(); and you'll get the value and you could use it like this:
echo $MyClass->ipAddress or echo $MyClass->proxyAddress but I would do it in a constructor of that class, the class constructor is a function/method of that class and needs to have the same name as the class in other languages it also can be init() like on Zend framework on PHP.. A constructor here is good because this function needs to be done/executed/called only once, also it could be done differently as I said, but this is just one of a lot of methods which is possible.




