Getting country from IP address JavaScript vs PHP

Hi guys,

I’m going to get the user location base on their IP address and redirect accordingly. This will use the third party service.

Which one is more efficient between JavaScript and PHP?

Which one is faster?

My concern is latency and I can’t find answer on Google.

Thank you,

PHP is more reliable (can’t be turned off) and it can detect the IP address before the page is even sent to the browser, making the redirect more efficient. That’s my take, anyway.

1 Like

PHP has direct access to the IP address.

For JavaScript to be able to access the IP address a server side language (or Java running client side) needs to first retrieve it and then pass it to JavaScript as JavaScript can’t access it directly itself.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.