Sessions 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
user___
Forum Contributor
Posts: 297
Joined: Tue Dec 05, 2006 3:05 pm

Sessions problem

Post by user___ »

hI GUYS,
i HAVE A REDIRECT FILE redir.php
which uses session_start();
then
$_SESSION['username'] = "username";
$_SESSION['password']="password";
then header(Location:http:localhost/...");

When I am redirected after IO have called session_start();
and echo $_SESSION['username'];
I get no result;
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

Is session_start() at the very top of both PHP files?

What do you see if you put

Code: Select all

print_r($_SESSION);
in the file?
user___
Forum Contributor
Posts: 297
Joined: Tue Dec 05, 2006 3:05 pm

Reply

Post by user___ »

No man. I have session_start() called at the top of my file(redir.php)
Then set sessions
Then Redirect.
When I print_r($_SESSION);
I have empty array:Array();
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

Are you setting the session variables under a condition?
user___
Forum Contributor
Posts: 297
Joined: Tue Dec 05, 2006 3:05 pm

Reply

Post by user___ »

No, I do not.

I do the same as I have told you.

Any suggestions?
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

I'd try changing as many things as possible to see if you can narrow down the problem. Try the same code on another server first of all, then try a different browser. Apart from those suggestions I'm all out.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Does PHP have permission to write to the directory that you've set to store session information?
user___
Forum Contributor
Posts: 297
Joined: Tue Dec 05, 2006 3:05 pm

Reply

Post by user___ »

Yes, it has. I see files created there. When I initialize session it is saved there as a file.

Eveything runs normally except this.
user___
Forum Contributor
Posts: 297
Joined: Tue Dec 05, 2006 3:05 pm

Reply

Post by user___ »

Ohps, I have said something which is not right. I have a file created on my Hard Drive but it is empty.

Any suggestions?
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Re: Reply

Post by aaronhall »

user___ wrote:I have a file created on my Hard Drive but it is empty.
What does that mean?
user___
Forum Contributor
Posts: 297
Joined: Tue Dec 05, 2006 3:05 pm

Reply

Post by user___ »

It means that a file(The usual file which is created when a session is called.) in the folder(Where sessions are stored,) is created but it is empty.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Using a redirection and sessions in the same script can have a short circuiting effect on the session. Try calling session_write_close().
user___
Forum Contributor
Posts: 297
Joined: Tue Dec 05, 2006 3:05 pm

Reply

Post by user___ »

I have tried it but no result so far. When I use a link it works. When I use a redirection it does not.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Post the full code from redir.php ... there's obviously something weird going on in it.
user___
Forum Contributor
Posts: 297
Joined: Tue Dec 05, 2006 3:05 pm

Reply

Post by user___ »

Hi guys,
I have fixed it to some extent. I have removed everything and left just these three lines of code and it worked but not on myt localhost and after I have checked the server's logs I saw an error:Premature end of script headers but I do not know what might have caused it.
Any suggestions.
Post Reply