Skip to content Skip to sidebar Skip to footer

What Is The Difference Between Php Header And Javascript Window.location?

So yeah this came to mind randomly when I was teaching someone how to redirect their page. I wasn't really sure what the main difference was... Is there a reason you would use one

Solution 1:

The browser will process the header redirect right away, whereas the Javascript redirect will not be executed until the page has loaded (or at least enough of it to run the Javascript). Also, it will be the Javascript engine executing the redirect instead of the browser itself.

Doing it via the header will perform better. (slightly anyway...)

Solution 2:

PHP's server-side header can send other headers then only Location. Javascripts client-side window.location can be used to read, inspect, and alter (parts of the) current url, including hash. Really, they can do quite different stuff, and about their only overlap is both being able to redirect.

Post a Comment for "What Is The Difference Between Php Header And Javascript Window.location?"