in reply to Effective request simulation from various location
Basically, users can visit the website from different countries. And based upon the location of the user, the site displays relevant information.
That should be "based on the assumed location of the user."
I would suggest that you consider giving a little more control to the user regarding what is relevant. By all means provide content based on the location of the IP address, but also provide a means to provide alternative content if this is not relevant.
You need to consider that the IP address that you are seeing may be nowhere near the user - they may be connected through a VPN (for instance, bypassing 'the Great Firewall of China',) running through an anonymising service like tor or through a gateway connecting a private corporate network with the Internet at large. Assume away but let the user have the choice to correct your assumption if they so wish ;-)
As regards the logic of proxies, this is something with which you should probably familiarise yourself anyway. The environment variable $ENV{'REMOTE_ADDR'} is very often showing you a proxy (especially with ISPs that use transparent proxies, corporate networks again, etc.) rather than the IP address of the user. Which may be in a quite different geographic location from the user, if not in a different country.
I would suggest that you Google for X-Forwarded-For, the non-RFC-standard header used by many (but by all means not all) proxy servers to identify the 'real' IP of the client. This should be available to you - if set - as $ENV{'X-FORWARDED-FOR'}; note that this might come out as an array, as I believe that the header can have up to three parameters (if I remember correctly). There is another, similar, header that is sometimes used to perform the same function, but I can't remember it off the top of my head. You may come across it reading up on X-Forwarded-For.
And welcome to Perl Monks :-)
|
---|