Forum Moderators: coopster

Message Too Old, No Replies

Login / Log out - need to refresh page?

small issue for someone who's used to building login pages

         

le_gber

6:11 pm on Jul 4, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi guys,

I got a login / logout script that resides on the same page. Basically if the URI includes action=logout I call a logout function that kills all the session variables. Otherwise I try to log in using the posted data, or do nothing if the form wasn't posted.

My problem is that I have somewhere on the page a small piece of code that says: 'You are logged in - <link>logout</link>'.

Now upon successful login this piece of code does not appear (until I refresh the page or navigate away from it) and similarly the piece of code still appears once I am logged out (until I refresh the page or navigate away from it).

Could anyone point me in the right direction to fix this, it's driving me nuts.

phparion

4:31 am on Jul 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



you would probably be checking the session values to show this logged in . once you click on logout you just call a function on the same page which must be called after displaying this message based on session therefore at the time of displaying it your session values are alive and after that you kill the session.

what you can do is to use header() to refresh the page on logout and login events then the message will be updated successfully.

a very hard subway could be to use javascript / ajax and put your this message in a div. check at the bottom / end of the page if the session value is alive or killed (Logged in or not) and then update the div value with javascript call.

eelixduppy

5:15 pm on Jul 5, 2007 (gmt 0)



Sounds just like a logic error to me. Check where you are echoing the link to logout and how you're destroying the sessions. Somewhere in there you are doing stuff in the wrong order. The first thing you should be checking for is if the person is logged in, and if they are, if they want to log out; if they do, log them out and if not, continue to display the content. If the session variables are not defined, proceed with validating the username and password.