tags:

views:

65

answers:

4
<?
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  A: 

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

Dennis Baker
+8  A: 

Script execution continues after setting a Location: header (or any other call to header(), for that matter). If you want the redirect to happen immediately, without the rest of the script executing, return; or die; immediately after you call header().

Frank Farmer
+1 And i would also set the cookie before sending the redirecting header.
rmontagud
A: 

have you got error reporting turned off, that would help you out with the syntax error and is always worth doing in a dev environment.

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

EDIT: there was a syntax error with a double semi-colon but that seems to have been corrected

you also need to call exit() after your header or script execution will not stop and the cookie will be sete

seengee
+1  A: 

Try this:

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

The page (including your headers) only gets sent after 'all' your php is executed (unless you tell it to stop with die() or exit());

ChristopheD