Curious...

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
Gannyaa
-


Joined: 29 Sep 2006
Posts: 93
Location: Nelson, BC -- Canada

PostPosted: Fri Mar 16, 2007 3:58 am    Post subject: Curious... Reply with quote

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 View user's profile Send private message Send e-mail Visit poster's website
AbyssUnderground
-


Joined: 31 Dec 2004
Posts: 3855

PostPosted: Fri Mar 16, 2007 8:41 am    Post subject: Reply with quote

Try storing the session data in a variable and reading the variable.
_________________
Andy (AbyssUnderground) (previously The Inquisitor)
www.abyssunderground.co.uk
Back to top View user's profile Send private message Visit poster's website
Gannyaa
-


Joined: 29 Sep 2006
Posts: 93
Location: Nelson, BC -- Canada

PostPosted: Fri Mar 16, 2007 3:24 pm    Post subject: Ya... Reply with quote

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 View user's profile Send private message Send e-mail Visit poster's website
cmxflash
-


Joined: 11 Dec 2004
Posts: 872

PostPosted: Fri Mar 16, 2007 5:56 pm    Post subject: Reply with quote

It's $_SESSION['name'], not $_session("name").
Back to top View user's profile Send private message
Gannyaa
-


Joined: 29 Sep 2006
Posts: 93
Location: Nelson, BC -- Canada

PostPosted: Fri Mar 16, 2007 6:41 pm    Post subject: your right cmxflash Reply with quote

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 View user's profile Send private message Send e-mail Visit poster's website
pkSML
-


Joined: 29 May 2006
Posts: 952
Location: Michigan, USA

PostPosted: Sat Mar 17, 2007 3:46 am    Post subject: Reply with quote

Maybe it's a cookie problem!

If you're testing this on localhost, cookies don't work quite the same. Cookies on localhost work differently since it's not a domain. See http://www.aeonity.com/frost/php-setcookie-localhost-apache and http://www.phpfreaks.com/forums/index.php?topic=131534.msg553830#msg553830

For some troubleshooting advice, access the script in question through the internet rather than localhost. You might also print the session variables with this code
Code:
<?php
echo "<PRE>";
print_r($_SESSION);
echo "</PRE>";
?>


Also, check to see if you're actually receiving a cookie. With IE, you can check the HTTP headers with this program --> http://www.blunck.se/iehttpheaders/iehttpheaders.html
_________________
Stephen
Need a LitlURL?


http://CodeBin.yi.org
Back to top View user's profile Send private message Visit poster's website
Gannyaa
-


Joined: 29 Sep 2006
Posts: 93
Location: Nelson, BC -- Canada

PostPosted: Sat Mar 17, 2007 5:44 pm    Post subject: Thanks pkSML! Reply with quote

What a great forum link that PHP Freaks one...

Certainly must be my php.ini and local host setcookies... I am looking into it. Now that I have some better tools to work with... :o

Thanks again pkSML!
_________________
Todd (Gannyaa)
http://iGannyaa.bebo.com/
http://haidavision.no-ip.info/gannyaa/newblog.htm
Back to top View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group