Trouble baking a cookie with a redirect.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ridshack
Forum Commoner
Posts: 29
Joined: Wed Oct 11, 2006 10:34 pm

Trouble baking a cookie with a redirect.

Post by ridshack »

When a user gets redirected for not having yet logged in I want to pass the page they where trying to access so when correctly authenticate I can send them back to where they came, but I cant seem to set a cookie this cookie.

I really appreciate any guidance. Also if you think I should be doing this all different then please let me know what you suggest.

Page 1

Code: Select all

<?php
$value = "https://www.web.com/office/admin/queries.php";
setcookie("TestCookie", $value);

//Only Allows Authenticated users to access the page
$Techs = $_COOKIE["Techs"];
if(!isset($Techs)) {
$page = "https://www.web.com/office/admin/queries.php";
setcookie("page",$page);
}
?>
Try to display the cookie here and it appears not to be set. As it does not echo the cookie value.

Page 2

Code: Select all

<html>
<head>
<meta http-equiv="refresh" content="2; URL=https://www.web.com/office/DB_authenticate.php">
</head>
<body>
<?php
echo "You must first login.";
echo $_COOKIE["TestCookie"]; //This just to see if the cookie is working

?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Using a header level redirection can often short circuit any other header operations that may be in there for many browsers. It may be best to use sessions to transfer this information. You may need to include session_write_close() if you go that path as well.
Post Reply