Weird session problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
etonB
Forum Newbie
Posts: 2
Joined: Sun Mar 21, 2010 10:08 pm

Weird session problem

Post by etonB »

I'm making a small website where an admin has special functions. I've managed to make my login/logout scripts with sessions and able to show the admin's special functions only to him.

The problem is when logging out and back in, it gets really weird. This is how I can come accross the error:

1. Enter my website
2. Log-in as 'admin'
3. Click on Add News (the special functions)
4. At this point, things work perfect, I can add news and go back to main page.
5. Log-out
6. Log-in as 'admin' again
7. Click on Add News
8. At this point, I get logged out and can't add news obviously until I log in again.

This is how I perform log-out

Code: Select all

<p class="textoIngresar">Welcome, <?php echo $_SESSION["loggedUser"];?> ( <a href="index.php?action=logout">Log-out</a> )</p>
This is the actual log out function

Code: Select all

if ( $_GET["action"] == "logout") 
    {
        session_unset();
        session_destroy();
    }
Am I doing the logout wrong? I need to know if that part is ok so I can look for errors elsewhere.

Thanks in advance,
etonB.
etonB
Forum Newbie
Posts: 2
Joined: Sun Mar 21, 2010 10:08 pm

Re: Weird session problem

Post by etonB »

Bump, really need input on whether or not I'm doing the log-out right.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Weird session problem

Post by Darhazer »

Your login code and how you are checking if the admin is logged in?
Post Reply