![]() |
Sessions Problem
I'm trying to learn more about PHP sessions, as I'm going to be using them in a website I'm building soon.
Anyways, my problem with them is that I'm wondering how I can make them last after the user's browser is closed. Here is a code example: :
<?phpThen obviously I would view the session on another page with code like this: :
Now, as I understand it... sessions are stored in a cookie on the user's browser so that other scripts can use them and such. The above code always works, and I can go to another page and come back and it still works. But, if I close my browser and I come back to the page that views the session variables, they aren't set anymore. I've tried changing settings like session:cookie.lifetime, session:cookie.expire, etc. but so far, I've pretty much had no luck. I've searched with google thoroughly and checked the PHP manual, and I haven't found anything that's helped me out. So, anyone have anything that'll help me out? Basically, I'm going to be using sessions with MySQL for authentication and such, so I figured it would be nice to have users logged in when they come back after closing their browsers. I assume this is possible, as I've seen it before, but perhaps the websites were using something different? |
Re: Sessions Problem
|
Re: Sessions Problem
Alright, I guess I misunderstood what sessions did... thanks for your help.
|
Re: Sessions Problem
Alright, so now I'm working on the actual authentication script for my website, and I'm using cookies. I tested out cookies, and I had them working, but now when I try it, it isn't working.
Here is my code: :
while ($result=mysql_fetch_array($query)) {I basically just have it looping through a mysql query looking to match a username and password, and then it puts it into a cookie, then a session cookie and a variable. It wasn't working, so I used print_r to view what's in the $_SESSION and $_COOKIE global array, but there was nothing in it. Any thoughts on why exactly it doesn't work? |
Re: Sessions Problem
are the passwords in your database encrypted? or rather are you encrypting the pass on its way to the query? any mismatch of encryption would throw it.
|
Re: Sessions Problem
I'd like to see the code before that segment - problem could be up there.
|
Re: Sessions Problem
Well, I used the sha1() function to encrypt the password, but I have the same thing in the database.
For example, the password for the user I am testing with is asdfasdf, which is changed to: 92429d82a41e930486c6de5ebda9602d55c39986 The password in the database is also: 92429d82a41e930486c6de5ebda9602d55c39986. I don't think the password is a problem, because it gets through the loop and it gets to the part where it has print_r($_SESSION) But, it shows a blank array. |
Re: Sessions Problem
Have you called
session_start? |
Re: Sessions Problem
I'm pretty sure I have... and I'll check now... but is session_start() necessary for cookies to work?
EDIT: Just checked... printing the $_COOKIE array does display a session ID, therefore I can safely assume that I started it. |
Re: Sessions Problem
I'm not going to comment on the rest of it yet, but I will say that you should look in to WHERE clauses in SQL. Looping through all user records is bad. Tell the database which one you are looking for.
|
| All times are GMT -5. The time now is 4:21 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC