bestrong Posted July 29, 2009 Share Posted July 29, 2009 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? Quote Link to comment Share on other sites More sharing options...
bestrong Posted July 29, 2009 Author Share Posted July 29, 2009 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 ??? Quote Link to comment Share on other sites More sharing options...
bestrong Posted July 29, 2009 Author Share Posted July 29, 2009 Please help, I am supposed to get this fixed today Quote Link to comment Share on other sites More sharing options...
p2grace Posted July 29, 2009 Share Posted July 29, 2009 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. Quote Link to comment Share on other sites More sharing options...
bestrong Posted July 29, 2009 Author Share Posted July 29, 2009 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 Quote Link to comment Share on other sites More sharing options...
p2grace Posted July 29, 2009 Share Posted July 29, 2009 What is the code at those lines? Quote Link to comment Share on other sites More sharing options...
bestrong Posted July 29, 2009 Author Share Posted July 29, 2009 line 8 = if($_COOKIE['bbs_remember_me']==1){ line 24 = if($_SESSION['session_id']!=''){ Quote Link to comment Share on other sites More sharing options...
bestrong Posted July 29, 2009 Author Share Posted July 29, 2009 also, even if i open a new browser tab, and go to the same site, it does not recognize the cookies. Quote Link to comment Share on other sites More sharing options...
p2grace Posted July 29, 2009 Share Posted July 29, 2009 The errors are generated because the variables aren't set when you're trying to determine what they're values are. Is this a public page that we can test? Quote Link to comment Share on other sites More sharing options...
bestrong Posted July 29, 2009 Author Share Posted July 29, 2009 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?? Quote Link to comment Share on other sites More sharing options...
bestrong Posted July 29, 2009 Author Share Posted July 29, 2009 Hmmm, It now seems to work in IE, but not firefox. Why would it make a difference?? Quote Link to comment Share on other sites More sharing options...
p2grace Posted July 29, 2009 Share Posted July 29, 2009 Are you using the Web Developer toolbar in firefox? Is it possible you've disabled cache? Quote Link to comment Share on other sites More sharing options...
bestrong Posted July 29, 2009 Author Share Posted July 29, 2009 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! Quote Link to comment Share on other sites More sharing options...
p2grace Posted July 29, 2009 Share Posted July 29, 2009 Adding the "/" to your setcookie should've fixed that issue. That's what happens when the cookies aren't stored globally. Quote Link to comment Share on other sites More sharing options...
bestrong Posted July 29, 2009 Author Share Posted July 29, 2009 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? Quote Link to comment Share on other sites More sharing options...
bestrong Posted July 29, 2009 Author Share Posted July 29, 2009 ...again, this is only the case in firefox Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.