0

I have a cookie script that creates a cookie from a session variable, the only problem is when the session is destroyed the cookie is deleted even though I set the expiration to a year. What can I do to prevent this?

2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by Tekkno
0

Are you sure? Normally, when using session_destroy() the cookie isn't deleted - you have to do it manually. Maybe, you can post your code here, so that people get an ideo of your problem.

0

Yes, I am sure. I logged in, checked, and the cookie was there. I logged out, checked, and the cookie had been deleted. Here is my cookie script:

<?php if(isset($_SESSION['theme']));
$theme = $_SESSION['theme'];
setcookie(theme,$theme,time()+(60*60*24*365));
?>

Here is my logout script:

<?
session_start();
if($_SESSION["uname"]<> "") {
session_unset();
session_destroy();
header( "Location:index.php" );
exit();
}
?>

Could it be because I am using isset to set the cookie possibly?

Well it's not the isset. Here is the revised code:

<?php if($_SESSION['theme']);
$theme = $_SESSION['theme'];
setcookie(theme,$theme,time()+(60*60*24*365));
?>

It's as if PHP is treating it as a session cookie.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.