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
Randwulf
Forum Commoner
Posts: 63
Joined: Wed Jan 07, 2009 7:07 am

Session Problem

Post by Randwulf »

Hullo,

I'm having a problem with sessions. My user's are having to login twice.

Here's the chunk of my login php file where sessions are assigned:

Code: Select all

    
if ($arr['Password'] == $pwHashed)
    {
        session_start();
        $_SESSION['FileP'] = strtolower(str_replace(" ","",$arr['SLName']));
        $_SESSION['Password'] = $pwHashed;
        $_SESSION['Username'] = $uid;
    }
    else
    {
        die ("Invalid Password.");
    }
    header("Location: http://(***************");
And then in the *********** file that the login one headers to, one of the first lines of code run is:

Code: Select all

extract($_SESSION) or die("<a href='http://*****************'>Log in</a>");
Am I just trying to extract the session too quickly after it's initiated? If my users log in again, all works fine.

Thank you.
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Session Problem

Post by Eric! »

And then in the *********** file that the login one headers to, one of the first lines of code run is:
Are you calling session_start in the ***** file before accessing your session data?
Randwulf
Forum Commoner
Posts: 63
Joined: Wed Jan 07, 2009 7:07 am

Re: Session Problem

Post by Randwulf »

Eric! wrote:
And then in the *********** file that the login one headers to, one of the first lines of code run is:
Are you calling session_start in the ***** file before accessing your session data?
Thank you for your response. Yes, I'm calling it before accessing the session data. Any other ideas? :(
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Session Problem

Post by Eric! »

I'm stabbing in the dark because I don't know what your two php scripts are doing by only seeing a line or two.

Check the basics, are the variables assigned right? Echo them to check.
Randwulf
Forum Commoner
Posts: 63
Joined: Wed Jan 07, 2009 7:07 am

Re: Session Problem

Post by Randwulf »

The thing is that the *** script dies and sends the user back to the login page, and if they log in again, it works fine. So it's not something syntax related or anything.
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

Re: Session Problem

Post by Eric! »

It never hurts to check them. I can't help much without seeing more code.

Extract is supposed to return the number of variables converted. Have you checked that the session variables are really not stored before running extract? Have you checked that extract is really returning 0? I've never used or die with extract....
Randwulf
Forum Commoner
Posts: 63
Joined: Wed Jan 07, 2009 7:07 am

Re: Session Problem

Post by Randwulf »

Yeah. I've tried all sorts of stuff :(

I think it might be something with my webhost. I'll contact them.
Post Reply