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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Cookie Issue

Status
Not open for further replies.

GT8203

Programmer
Joined
Jan 17, 2005
Messages
3
Location
US
I am having problems with the setcookie function initializing and timing out cookies using internet explorer 6. The following code is in my index file:

<?php
header(“P3P: CP=TELa OUR SAM PUR FIN DSP ALL COR");
header(Set-Cookie: f=abc; Max-Age=10; path=/);
header("Set-Cookie: e=dfg; Max-Age=90; path=/; Version=1");
setcookie('a', '1', time() + 8);
setcookie('b', '2', time() + 8, '/');
setcookie('c', '3', time() + 8, '/');
setcookie('timeout', 'time()+3600');
setcookie("time", "time");

php?>

I then use this form from the index page to go to the next page so that I can see the values in the cookies:

<form name="form1" method="post" action="showset.php">
<input type="submit" name="Submit" value="Show Cookie Value">
</form>

On the next page, I just echo the cookie values:

echo "cookie set using 'setcookie': " . $_COOKIE['a'] . '<br />';

However, only 3 of the cookies are set up (a, b, abc). Also, none of them expire. Can anyone please lend me some suggestions??

Thanks
 
You have some syntax errors in your code:
Code:
<?php    
    header("P3P: CP=TELa OUR SAM PUR FIN DSP ALL COR");        
    header(Set-Cookie: f=abc; Max-Age=10; path=/);
// missing quotes in the above line
    header("Set-Cookie: e=dfg; Max-Age=90; path=/; Version=1");
    setcookie('a', '1', time() + 8);
    setcookie('b', '2', time() + 8, '/');
    setcookie('c', '3', time() + 8, '/');
    setcookie('timeout', 'time()+3600');
// There is no time out on the about set
    setcookie("time", "time");    
php?>

For the code to display the cookies, use
Code:
<?
echo '<pre>';print_r($_COOKIE);echo '<pre>';
?>

Your cookies 'a', 'b', and 'c' should expire 8 seconds after you create them.

Ken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top