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.
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.