Jump to content

Php Cookies deleting after page close - even with time set!


bestrong

Recommended Posts

Hello!

 

I am having a problem with cookies not saving correctly...

 

setcookie('remember_me', 1, (time()+31536000));

 

(along with several other cookies)

 

The problem is that my cookies are becoming non-existant after I close the browser...and re-open...they are not there...

 

any ideas?

To expound, it does not matter what  browser I'm using, also, in the code, I have

 

<?php
session_start();

if($_COOKIE['remember_me']==1){

setcookie('logged_in', 1, 7200 +time());

$_SESSION['logged_in'] = '1';
$_SESSION['first_name'] = $_COOKIE['first_name'];

}

?>

 

Works fine, but if I close the browser and come back, $_COOKIE['remember_me'] is null

 

???

 

 

 

 

 

Try this:

 

setcookie('SITE_remember_me', '1', (time()+31536000),'/'); 

 

<?php
session_start();

if(isset($_COOKIE['SITE_remember_me'] && $_COOKIE['SITE_remember_me']=='1'){
         
   setcookie('logged_in', 1, 7200 +time());
   
   $_SESSION['logged_in'] = '1';
   $_SESSION['first_name'] = $_COOKIE['first_name'];

}

?>


 

I added a folder path to the cookie.

 

You should put your site name in the front of your cookie so you don't have any conflict with other website cookies.

 

Let's start there, if it still doesn't work.  Display php errors and we can go from there.

I added the pat and a bbs_ prefix to all the cookies

 

if($_COOKIE['bbs_remember_me']==1){

setcookie('bbs_logged_in', 1, 7200 +time(),'/');

$_SESSION['logged_in'] = '1';

 

Php sends the notice

 

 

Notice: Undefined index: bbs_remember_me in /var/www/vhosts/dev.bluebeanstalk.com/httpdocs/includes/is_logged_in.php on line 8

 

Notice: Undefined index: session_id in /var/www/vhosts/dev.bluebeanstalk.com/httpdocs/includes/is_logged_in.php on line 24

well, the page is public, but you wont be able to test it because you have login to see the results, and creating new accounts is disabled on the dev site

 

I assumed thats what the errors were, but that is the whole thing, why the heck arent they set? it is confusing the heck out of me?

 

does it have something to do with session ids or something, so php is not recognizing that I am the same person??

 

 

No, cache is enabled, but I've found something out

 

Ok,

 

I log in in firefox, and I am redirected to http:/www.dev.bluebeanstalk.com/index.php

 

if I close the browser and go to http:/www.dev.bluebeanstalk.com (without the /index.php) the cookies are not there....

 

BUT

 

if I open a new window and type in http:/www.dev.bluebeanstalk.com/index.php , the cookies are there

 

Whats going on?

 

Thanks for all the help!

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.