php - How do I determine if the client is accessing the website through intranet or internet? -
the situation have wordpress install on iis 7.5 accesses internet through proxy , parts of website make client side external request (images, youtube videos etc.) needs users enter proxy credentials if accessing site through intranet.
i hide elements of site if accessed through intranet , have functional if accessed through internet.
i found this answer helped bit (and yes changed local_addr
because of iis) fails because of proxy.
internet requests site go through proxy on same network, thinks every request intranet request.
so, how can improve function work in situation if know proxy ip?
function is_intranet() { $serverip = explode('.',$_server['local_addr']); $localip = explode('.',$_server['remote_addr']); return ( ($serverip[0] == $localip[0]) && (in_array($serverip[0],array('127','10','172','192') ) ) ); }
proxy? suppose mean reverse-proxy. if so, many reverse proxies add http headers original request. check if request headers contain "x-forwarded-for" http://en.wikipedia.org/wiki/x-forwarded-for
in general, last item you're looking for.
c# example:
string xff = request.headers["x-forwarded-for"]; if (xff != null) { string[] clientiplist = xff.split(','); string ip = clientiplist.last(); }
Comments
Post a Comment