How to redirect users to a page in PHP

If you want to redirect users to a specific page or url like when user is not logged in or something in PHP then you can accomplish this with header function or by Javascript printed by echo function. The following example will redirect user to Or you can use the normal Javascript : window.location=’’;”; ? What’s the difference ? header function is called in server itself not when the page reaches the browser.