Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP which is the best practise of header location

I have a confusion in using PHP header location. which way is best practice...?

if(true){
    header("location:somepage.php");
}

or

if(true){
    header("location:somepage.php");
    exit;
}  
like image 233
Ravi MCA Avatar asked Jan 27 '26 07:01

Ravi MCA


1 Answers

After sending the `Location:' header PHP will continue parsing, and all code below the header() call will still be executed. So instead use your second example:

if(true){
       header("location:somepage.php");
       exit;
  }
like image 157
Daan Avatar answered Jan 29 '26 20:01

Daan