If you want that info for JS, try the geolocation feature of HTML5. This is the example for getting user location: http://www.w3schools.com/html5/html5_geolocation.asp. With this method, you can find the longitude and latitude of user location, however, the accuracy is not guaranteed. And more than that, you have to use additional thing like Google Maps API to get more information about this combination of longitude and latitude like country name, city name, etc.
For server, user location can be recognised by deciding at which range the IP belongs to. The database of IP ranges can be downloaded from here (26.3 MB): http://www.hostip.info/dl/index.html
Or follow the instructions in the link provided Moyed Ansari at the first comment below the question.