View previous topic :: View next topic |
Author |
Message |
Gannyaa -
Joined: 29 Sep 2006 Posts: 93 Location: Nelson, BC -- Canada
|
Posted: Fri Mar 16, 2007 3:58 am Post subject: Curious... |
|
|
Hello,
I ran into an interesting problem with sessions. Here in my php imagebuilder file I echo with php. The session_start() is declared in the imagebuilder.php file.
<?php
echo("<br /><img src='/dir/scripts/imagebuilder.php' border='1' />");
?>
<div>
<br />Later on in this file I check the $_session("pass") and it is empty.
</div>
<?php
if (isset($_session("pass")) {
echo("pass =" . $_session("pass"));
} else {
echo("pass = null");
}
?>
So before the isset check, I insert another session_start() then check the session pass and it is not null !!! PHP generates an error log stating that you cannot declare a session twice! What gives, it works if I do declare the session twice, and it won't work if I declare the session once. Hmmmm..
Later _________________ Todd (Gannyaa)
http://iGannyaa.bebo.com/
http://haidavision.no-ip.info/gannyaa/newblog.htm |
|
Back to top |
|
|
AbyssUnderground -
Joined: 31 Dec 2004 Posts: 3855
|
Posted: Fri Mar 16, 2007 8:41 am Post subject: |
|
|
Try storing the session data in a variable and reading the variable. _________________ Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk |
|
Back to top |
|
|
Gannyaa -
Joined: 29 Sep 2006 Posts: 93 Location: Nelson, BC -- Canada
|
Posted: Fri Mar 16, 2007 3:24 pm Post subject: Ya... |
|
|
Yes of course... The imagebuilder.php file starts the session, then stores a random session string in "pass". To call the variable out of the session data, you have to start the session again. PHP then logs an error stating that the session can only be started once. Since it is so minor, I turned errorreporting off for just that page using: error_reporting(0);
I've checked about 20 other php scripts with sessions, and the all start sessions to put data in, start a session to read data. Most of the scripts have error_reporting turned off.
Just curious...
and its definitely not a browser cache, or temporary file problem. _________________ Todd (Gannyaa)
http://iGannyaa.bebo.com/
http://haidavision.no-ip.info/gannyaa/newblog.htm |
|
Back to top |
|
|
cmxflash -
Joined: 11 Dec 2004 Posts: 872
|
Posted: Fri Mar 16, 2007 5:56 pm Post subject: |
|
|
It's $_SESSION['name'], not $_session("name"). |
|
Back to top |
|
|
Gannyaa -
Joined: 29 Sep 2006 Posts: 93 Location: Nelson, BC -- Canada
|
Posted: Fri Mar 16, 2007 6:41 pm Post subject: your right cmxflash |
|
|
Your right cmxflash,
What I am trying to say is that the error is in starting the session twice.
Sorry for my typo, the page works even though I copied it wrong as an example. Don't try fixing the example, try duplicating the error. _________________ Todd (Gannyaa)
http://iGannyaa.bebo.com/
http://haidavision.no-ip.info/gannyaa/newblog.htm |
|
Back to top |
|
|
pkSML -
Joined: 29 May 2006 Posts: 952 Location: Michigan, USA
|
|
Back to top |
|
|
Gannyaa -
Joined: 29 Sep 2006 Posts: 93 Location: Nelson, BC -- Canada
|
|
Back to top |
|
|
|