Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cookie question

Status
Not open for further replies.

skiflyer

Programmer
Sep 24, 2002
2,213
US
Is it possible to write a cookie which never expires?

setcookie("email", $email, ????);

-Rob

Thanks.
 
Alright, that works... second question... why won't my cookie work?!

I have a page which processes a form, then flops you back to where you started... so my first line is.

setcookie("email",$email, 36000000);

then alot of php

then

Header("Location:

And it's quite clear to me what's going on, the cookie header info is being completely rewritten with the location header information. I suppose I could change my header info at the bottom to a javascript page with a startup function that redirects... but I like elegance, is there a way to combine the header info?
 
I doubt that the "Location" header is overwriting the "Cookie" header. Both are valid headers, and you can send many headers in a single transaction.

Here's a pair of test scripts I just wrote:
[/i]test_cookie1.php[/b]:
Code:
<?php
setcookie (&quot;foo&quot;, &quot;bar&quot;, time() + 3153600000);
header (&quot;Location: /test_code/test_cookie2.php&quot;);
?>

test_cookie2.php:
Code:
<?php
print '<pre>';
print_r ($_COOKIE);
?>

And here's my output from test_cookie2.php:
Code:
Array
(
    [foo] => bar
)

Which is what I expect. Are you redirecting to a location for which the cookie you've set is valid? Want the best answers? Ask the best questions: TANSTAAFL!
 
That's your output? Not mine, I get old values from other cookies I set, but [foo] remains unset for me when I run your code. Must be a version or setup thing... well nice to know I was doing it right anyway.

4.2.3, IIS4

Cookie settings as defaulted.

-Rob
 
Yeah, was definately some problem with the header call... either an overwrite or just botching the two... I took the easy way and just used javascript for the redirect and all is fine... strange that is. Mayhaps I should've looked into headers_sent... but I'm up now.

-Rob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top