how to php redirect ?

In this artcle we are explaining how to redirect a php page to another location, Sometimes we need to redirect our php page to another after executing some code. For example , redirect to dashboard page after login check process

  • Step1 : Prerequisite
    Make sure that, there is no white space in the first line of the php file. Basically we have to makesure that nothing is printing to buffer before redirect.
  • Redirect Function call
    Use the php function called header to redirect to another url.
    Example: header('location: target-page.php');
  • Terminate the current script
    Use exit(); function to terminate the current script

    Full code

    <?php // write your codes before start the redirection
    header('location: target-page.php');
    exit();
    ?>