note 34359 modified in function.header by nicos

From: Date: Fri, 25 Jul 2003 09:36:26 +0000
Subject: note 34359 modified in function.header by nicos
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-52626@lists.php.net to get a copy of this message
[Editor's note: to avoid this, just put the second header() call in a "else { }". ] If you omit the "exit;" call after each redirection header, they will essentially pile up, each execute, and you will be redirected to the location of the last one . I have noticed this common mistake among novice programmers. It is important to note that a header("Location:page") command does stop the rest of the page from processing. ** THE FOLLOWING CODE IS WRONG ** if ($x == 1) { header("Location: page1.php"); } header("Location:default.php"); ** SHOULD BE: ** if ($x == 1) { header("Location: page1.php"); exit; } header("Location:default.php"); exit; --was-- If you omit the "exit;" call after each redirection header, they will essentially pile up, each execute, and you will be redirected to the location of the last one . I have noticed this common mistake among novice programmers. It is important to note that a header("Location:page") command does stop the rest of the page from processing. ** THE FOLLOWING CODE IS WRONG ** if ($x == 1) { header("Location: page1.php"); } header("Location:default.php"); ** SHOULD BE: ** if ($x == 1) { header("Location: page1.php"); exit; } header("Location:default.php"); exit; http://www.php.net/manual/en/function.header.php

« previous php.notes (#52626) next »