I would like to get the visitor's ip address.
Which one is the appropriate one to use:
Request.ServerVariables("REMOTE_ADDR")
or
Request.UserHostAddress
Which one is the best method?
I would like to get the visitor's ip address.
Which one is the appropriate one to use:
Request.ServerVariables("REMOTE_ADDR")
or
Request.UserHostAddress
Which one is the best method?
They're exactly the same. UserHostAddress
simply calls GetRemoteAddress
.
public string UserHostAddress
{
get
{
if (this._wr != null)
{
return this._wr.GetRemoteAddress();
}
return null;
}
}
public override string GetRemoteAddress()
{
return this.GetServerVariable("REMOTE_ADDR");
}
Both are also supported from .NET Framework 1.0/1.1 onward.
Try using
phpinfo();
It should give you something like REMOTE_ADDR which is the variable you need to grab in your php script. This should be passed from the webserver to your PHP script.
Then use:
$ip = getenv('REMOTE_ADDR');