954,576 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Question about cookies

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?

Tekkno
Junior Poster
134 posts since Apr 2009
Reputation Points: 12
Solved Threads: 7
 

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.

sDJh
Posting Whiz in Training
259 posts since Aug 2005
Reputation Points: 56
Solved Threads: 29
 

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.

Tekkno
Junior Poster
134 posts since Apr 2009
Reputation Points: 12
Solved Threads: 7
 

nobody?

Tekkno
Junior Poster
134 posts since Apr 2009
Reputation Points: 12
Solved Threads: 7
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You