Based on an incomming request for a web page, the server may want to detect the origin of that request in several ways.
Identify the IP adress of the HTTP request. The IP address will always be available, unless the connection is closed, before the point where it is read by your server.
The IP address may be IPv4 or IPv6, depending on what server listens on.
The IP address may not be accurate, if your request is hidden by means of a Web Proxy or a VPN connection, or if your IP address is taken randomly from a shared pool (DHCP).
In case of passing the request through a Web Proxy, it is often passed along with an IP address of the IP address that the Web Proxy saw as the requester. This may have a long line of IP addresses, if more Web Proxies are used. It may also contain bogus addresses passed in from the originating request. Validate the list carefully, before using.
The IP address, in itself, does not tell much about the location. But the following may get you closer to an actual location.
Look up the reverse DNS address from the IP address. This is not very exact, and can easily be faked. But in some cases it may give a hint of a company, or internet provider.
Look up the IP in the allocated ranges. Start at http://www.iana.org/numbers/.
Ask the client broser to find the current location. This usually requires the user to accept sharing the location with the web server. The location can usually be much more exact, especially if the device has a built-in GPS.
Ask the visitor (person) to type in their information. This is the most correct information, if you can trust the user to type in the right information.