Ok, I'm having the same problem, only now I know it's with sessions. This is what's happening, and I don't know the background mechanics of sessions/cookies to try a fix:
1. I'm at the main page and click a first link (long URL) to a first protected page in directory A.
2. I haven't logged in for a day, so the cookie has expired.
3. It takes me immediately to the login page, where I login. This is the only place where session_start(); is called.
4. The first protected page in directory A displays, and all is OK.
5. I use the browser back button to take me to the main page again.
6. Just to test to see if I'm really logged in, I click on the first link again, and the first protected page in directory A appears. Ah, fine, just like it's supposed to!
7. I use the back button again, and return to the main page.
8. Then click on a second link (long URL) to a second protected page in directory B.
9. The login page appears again, but it shouldn't have because I'm logged in, right?
10. I login again because I have no other choice, and the screen is blank, presumably because of an expected MySQL error in matching session data in the cookie to the password database. (see below.) So, somehow, I think the session has changed. How? Why? How do I keep it from changing?
11. I close the browser completely.
12. I open the browser again and go to the main page.
13. From here, I can click on both the first and second links and the protected page(s) display because the cookie is still set and I'm implicitly logged in, which is ok by me at this point, but totally unexpected because of the previous problem. Why is the session data OK now?
Something is going on with sessions that I don't understand. Using php 4.4.2
The blank screen is, I think, because of the 'or die()', at the top of each protected page. The blank screen URL is that of the protected page and not the login page, so after the second login, redirect is going to the right place:I'm totally frustrated because searching the web, I see that many people seem to have problems with cookies/sessions; I don't have anyone to talk to about this; the few others I know that use php listen and then abruptly change the subject to either the World Cup or Mets games. If you know what's going on, please, please give me some assistance. Thank you for reading all this.Code:function _check_auth($cookie) { $user = array(); $session = $cookie['SESSION']; $q = mysql_query(" SELECT user_id, user_name FROM sessions WHERE session = '".$session."' ") or die(mysql_error()); if(mysql_num_rows($q) == 0) header("Location: login.php"); else { $r = mysql_fetch_array($q); $user['user_id'] = $r['user_id']; $user['user_name'] = $r['user_name']; } return $user; }



Reply With Quote
I don't think that's the problem, but by all means check.
. The login.php script is this:
Bookmarks