Re-Direct A Page

syntax: 


  header ("location: http://" .     $_SERVER['HTTP_HOST'] .     dirname( $_SERVER['PHP_SELF']) .     "/newpage.php");



  • newpage - is the new page that you want to load or jump into and will make this the current page
  • dirname() - is a function local to PHP, that will return the current directory of the said parameter pass to it
  • $_SERVER['PHP_SELF'] - returns the current location of the current loaded script file, in this case the basis is the newpage.php file
  • $_SERVER['HTTP_HOST'] - returns or set the current Server name and info

  A more flexible method is to make use of the $_SERVER superglobal and the dirname() function (which returns the directory path of the current script).   This will effectively redirect the user to the current domain, current directory, and the current new page to be displayed on the browser.


  Oh, You need to add the exit() statement after the redirect statement to terminate the current script.   If omitted may result to unexpected problems.