Forum Moderators: coopster

Message Too Old, No Replies

Password/login problems

using $_POST[ ] and $_SESSION[ ]

         

Sarah Atkinson

8:41 pm on May 16, 2005 (gmt 0)

10+ Year Member



I have 4 pages I want users to have to enter a password to access. I have a userlogin page with a POST form. a prossesslogin page and an index page(where the user ends up after logging in.)

the user login page passes the username and password to the processing page. the processing page identifies if they match the MySQL DB. if it matches it includes the index page.

the index page has script at the top that check to see if $_SESSION['username'] is set and if so does nothing. if it doesn't exist then it includes the userlogin page and exits.

this is at the beginning of all pages not just the index page

my problem is that when changing the page the user is forced to logging again. this pretty much makes the pages useless.

Any idea why?
the $_SESSION[ ] array doesn't empty out when the page reloads does it?

dreamcatcher

8:48 pm on May 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you have session_start() on each page?

Sarah Atkinson

8:51 pm on May 16, 2005 (gmt 0)

10+ Year Member



no

Sarah Atkinson

8:53 pm on May 16, 2005 (gmt 0)

10+ Year Member



ok got it

mcibor

9:20 pm on May 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The first page not starting with session_start() deletes the session. Just add that and it should be working all right.

This function it is best to put first, because it might send a cookie and otherwise you may become an error: headers already sent

Hope this helps
Michal Cibor

dreamcatcher

9:46 pm on May 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yep, thanks mcibor, you need to have session_start() at the top of each page. Right after your opening <?php tag will do nicely.

Sounds like you got it sorted anyway.

dc