Jump to content
Larry Ullman's Book Forums



Recommended Posts

If a user is surfing your website, how is the best way to get a users two letter country code e.g "US" if we don't know where they are located?


I found the following options so far:








My website will require numerous API requests for this info so i am looking for a sensible solution.



Link to comment
Share on other sites

Thanks for the fast response.


I need such a request for such a page like eBay has for example




This is their listings page. If i know where a user is from by either locating their country or using their signed in account info, i could add data to item listings specific to them for example if the seller offered international shipping or had free shipping available. There also has to be a buffer just incase i can't find their location and then I could just provide default data for a particular item.


I really need the country to be picked up so it will work with my PHP script before the javascript even loads so i can perform specific page rendering.


Obviously if i do have to trigger an API request i wouldn't want to repeat it everytime the page had to be reloaded, so I would either need to issue the user with a Cookie or possibly save the IP's country from the proceeding API request to the database to later act as a IP country look up table.


Also i am unsure of what you mean by this? (If they're not (i.e., most desktop PCs), you can approximate their location by their IP address.) How can i find a users country via a IP address, i would need a lookup table or have to make a API request but from where exactly?

Link to comment
Share on other sites

Yes, for an IP address lookup, you would either need to hit up an API (the preferred option, since it's always up to date) or have a database for referencing.

Here's one such API you could use for IP address lookups:



The rest of what you need all sounds like business logic for your site and is pretty straightforward, so I'll let you handle all of that.

  • Upvote 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...