Title is ignored

<?
session_start();
$id = $_SESSION['id'];
$email = $_COOKIE['email'];
$password = $_COOKIE['password'];
header('Location: ../');
// I tell it to redirect...
$cookie_expires = time() + 60*60*24;
$cookie_path = '/';
$cookie_name = 'temporary';
$cookie_value = 'Your account was deleted.';
setcookie($cookie_name, $cookie_value, $cookie_expires, $cookie_path);
// ...but the cookie is set!
?>
<!-- Why? -->

      

+2


source to share


4 answers


Script execution continues after the header has been set Location:

(or any other call header()

, for that matter). If you want the redirect to be done immediately, without the rest of the script, return;

or die;

right after the call header()

.



+10


source


Cookies are sent as part of the header. The entire header is evaluated (including the cookie setting) and then the browser redirects.



+2


source


Try the following:

header('Location: ../');
exit();

      

The page (including your headers) is only sent after "everything" is done by your php (unless you tell it to stop working with die () or exit ());

+2


source


You have error reporting disabled, which will help you deal with syntax error and should always be done in the dev environment.

ini_set('display_errors',1);
error_reporting(E_ALL & ~E_NOTICE);

      

EDIT: There was a double semicolon syntax error, but seems to have been fixed

you also need to call exit()

after your header or script execution stops and the cookie is set

0


source







All Articles