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 :-)


In reply to Re: Effective request simulation from various location by smiffy
in thread Effective request simulation from various location by decebel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.