Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??
No, there's no $ENV{} type of variable you can use for this. You can, however, do a reverse DNS lookup on their connecting IP and see what their TLD is, matching this against a list of ISO country abbreviations. This won't help you with .com, .net, .edu or .org of course.

You can never be completely accurate since all you can verify is the region the IP address is registered in and the person themselves could be anywhere in the world.

Your best bet would be to follow some of the other suggestions in this thread and using the mentioned CPAN packages. You could also take a look at decent web log analysis packages and see how they do it.

It might be interesting to know exactly why you need to know this. If this is for user accounts, it will be useless since there is absolutely no reason your mailing address or residence would be in the same country as your IP address.

In reply to Re: How to check the origin ofi a visitor? by Seumas
in thread How to check the origin ofi a visitor? by cranberry13

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.