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?

Link to comment
Share on other sites

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

 

???

 

 

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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??

 

 

Link to comment
Share on other sites

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!

 

 

Link to comment
Share on other sites

hmm,

 

The cookies are created in dev.bluebeanstalk.com/login.php

 

maybe dev.bluebeanstalk.com is looked at as a parent folder or something ?

 

I have the "/"

 

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

 

any other ideas?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.