Forum Moderators: coopster
What I want to know is:
Will using $_SERVER['REMOTE_ADDR'] in PHP single my attacker down to one person/computer or will it sometimes read the network or router IP?
Kindest regards,
Tom.
$ip= isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
[edit]
That is same as
if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
in case there is any doubt over reusability and readability and what not, about the first code ;)
[/edit]
[edited by: Anyango at 9:14 pm (utc) on Dec. 11, 2008]
In simple words thats a compact version of an if/else statement, but lets forget that for now. Lets talk about the 2nd code.
It tries to see if user was using a proxy server ? if it was then it tries to get the actual ip of user and not of proxy server. If that case was false it simply gives you ip address of the user directly from REMOTE_ADDR.
Not really the best solution to block a user but answers your questions