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?

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.

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.

nobody?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.