Page 1 of 1
Sessions problem
Posted: Tue Mar 27, 2007 2:17 am
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;
Posted: Tue Mar 27, 2007 3:26 am
by impulse()
Is session_start() at the very top of both PHP files?
What do you see if you put
in the file?
Reply
Posted: Tue Mar 27, 2007 3:40 am
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();
Posted: Tue Mar 27, 2007 3:45 am
by impulse()
Are you setting the session variables under a condition?
Reply
Posted: Tue Mar 27, 2007 3:48 am
by user___
No, I do not.
I do the same as I have told you.
Any suggestions?
Posted: Tue Mar 27, 2007 4:01 am
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.
Posted: Tue Mar 27, 2007 5:24 am
by onion2k
Does PHP have permission to write to the directory that you've set to store session information?
Reply
Posted: Tue Mar 27, 2007 6:17 am
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.
Reply
Posted: Tue Mar 27, 2007 6:24 am
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?
Re: Reply
Posted: Tue Mar 27, 2007 8:20 am
by aaronhall
user___ wrote:I have a file created on my Hard Drive but it is empty.
What does that mean?
Reply
Posted: Tue Mar 27, 2007 8:26 am
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.
Posted: Tue Mar 27, 2007 8:56 am
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().
Reply
Posted: Tue Mar 27, 2007 9:04 am
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.
Posted: Tue Mar 27, 2007 9:06 am
by onion2k
Post the full code from redir.php ... there's obviously something weird going on in it.
Reply
Posted: Tue Mar 27, 2007 9:20 am
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.