Redirect a page using Javascript through PHP

/ Published in: PHP
Save to your folder(s)

Redirect page using PHP function.

I don't like using header() as I like to redirect page mid-page. This is implemented using Javascript written through PHP function. Has a die() function at the end for people who has disabled their Javascript in their browser.

Copy this code and paste it in your HTML
  1. function redirect($new_location){
  2. echo ("<script type='text/javascript'>
  3. document.location.replace('$new_location');
  4. </script> ");
  5. die();
  6. }

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.