tags:

views:

23

answers:

2

Hello,

I'm using a PHP / MySQL login system, and I'm having issues keeping the user logged in when I navigate around the site.

Would it help if I put session_start(); at the top of each page? (I'm looking for a quick-and-dirty / ham-fisted solution that works rather than an elegant one).

Thanks in advance,

John

+1  A: 

You need to put session_start() at the top of each page in which you want to use sessions. If you don't, the session is not available on that page.

deceze
+1  A: 

Sessions may use cookies but cookies can stand on their own. How are you setting the cookie? Cookies have an expiry and this needs to be set to a time in the future. I would check your browser info to see if the cookies are actually being set right. See the example below from the PHP docs for setcookie:

<?php
$value = 'something from somewhere';

setcookie("TestCookie", $value);
setcookie("TestCookie", $value, time()+3600);  /* expire in 1 hour */
setcookie("TestCookie", $value, time()+3600, "/~rasmus/", ".example.com", 1);
?>
BrianLy