I changed Yii’s CHttpRequest class so it suit my needs
for security reasons ( XSS protection, someone can send malicious code thru the header "host" and you might echo it without notice ), i changed the method getUserHost() to this
public function getUserHost()
{
return isset($_SERVER['REMOTE_HOST']) ? (preg_match("/^[a-zA-Z0-9\.-]+$/",$_SERVER['REMOTE_HOST'])? $_SERVER['REMOTE_HOST']:null):null;
}
also my need to get the real ip address even if the user is behind a proxy made me change the method getUserHostAddress() to this
public function getUserHostAddress()
{
switch(true){
case ($ip=getenv("HTTP_X_FORWARDED_FOR")):
break;
case ($ip=getenv("HTTP_CLIENT_IP")):
break;
default:
$ip=getenv("REMOTE_ADDR")?getenv("REMOTE_ADDR"):'127.0.0.1';
}
if (strpos($ip, ', ')>0) {
$ips = explode(', ', $ip);
$ip = $ips[0];
}
return $ip;
}
i actually use this code, its about 10-20 times faster, but it doesnt work if you on a IIS server:
public function getUserHostAddress()
{
switch(true){
case isset($_SERVER["HTTP_X_FORWARDED_FOR"]):
$ip=$_SERVER["HTTP_X_FORWARDED_FOR"];
break;
case isset($_SERVER["HTTP_CLIENT_IP"]):
$ip=$_SERVER["HTTP_CLIENT_IP"];
break;
default:
$ip=$_SERVER["REMOTE_ADDR"]?$_SERVER["REMOTE_ADDR"]:'127.0.0.1';
}
if (strpos($ip, ', ')>0) {
$ips = explode(', ', $ip);
$ip = $ips[0];
}
return $ip;
}
hope this helps someone