Jump to content

Archived

This topic is now archived and is closed to further replies.

mmtalon

Can't share SESSION variables. I need some help!

Recommended Posts

Can't share SESSION variables. I need some help!

Don't understand why this isn't working. Perhaps it is because I have the 2 files in 2 different directories? My register_globals is Off

Code example:

<?php
session_start();
// page1.php
$_SESSION['grncolor'] = 'green';
echo $_SESSION['grncolor']; // output works here
echo session_id(); // outputs session_id
// passing the session id - also tried absolute path with same results
echo '<br /><a href=\"../AA_dir/page2.php?' . SID . '\">page 2</a>';
?>

<?php
session_start();
// page2.php
//tried if(isset($_SESSION['grncolor'])) { negative }
echo $_SESSION['grncolor']; // green - will not output a value
echo session_id(); // outputs same session_id as in page1.php
echo '<br /><a href="../BB_dir/page1.php">page 1</a>';
?>

Share this post


Link to post
Share on other sites
This works for me. You seemed to have un-necessary bits in there.


<?php
session_start();
// page1.php
$_SESSION['grncolor'] = 'green';
echo $_SESSION['grncolor']; // output works here
echo session_id(); // outputs session_id
// passing the session id - also tried absolute path with same results
echo '<br /><a href=../bb/page2.php>page 2</a>';
?>


<?php
session_start();
// page2.php
//tried if(isset($_SESSION['grncolor'])) { negative }
echo $_SESSION['grncolor']; // green - will not output a value
echo session_id(); // outputs same session_id as in page1.php
echo '<br /><a href="../aa/page1.php">page 1</a>';
?>

Share this post


Link to post
Share on other sites
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]This works for me. You seemed to have un-necessary bits in there[/quote]
No, that's not un-necessary. That will propagate the session ID if the user disables cookies.

If it's outputting the same session id, I have really no idea on whats wrong.

Share this post


Link to post
Share on other sites
[!--quoteo(post=366445:date=Apr 19 2006, 10:00 AM:name=poirot)--][div class=\'quotetop\']QUOTE(poirot @ Apr 19 2006, 10:00 AM) [snapback]366445[/snapback][/div][div class=\'quotemain\'][!--quotec--]
No, that's not un-necessary. That will propagate the session ID if the user disables cookies.

If it's outputting the same session id, I have really no idea on whats wrong.
[/quote]
Thanks for the replies wisewood and poirot. I have checked the session id, which is spitting out the same id. I was thinking maybe I had missed some setting of some kind - e.g. php.ini etc. or maybe it's my ISP.

Tell me if I could be overlooking something. Also if you create your own sessions, how often do you use them and are they hard to construct?

Again, thanks a lot for your help.

Share this post


Link to post
Share on other sites
[!--quoteo(post=366513:date=Apr 19 2006, 12:41 PM:name=mmtalon)--][div class=\'quotetop\']QUOTE(mmtalon @ Apr 19 2006, 12:41 PM) [snapback]366513[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Thanks for the replies wisewood and poirot. I have checked the session id, which is spitting out the same id. I was thinking maybe I had missed some setting of some kind - e.g. php.ini etc. or maybe it's my ISP.

Tell me if I could be overlooking something. Also if you create your own sessions, how often do you use them and are they hard to construct?

Again, thanks a lot for your help.
[/quote]
I found out that I am overlooking something. It has something to do with my code and how it's structured. I know this after testing with 2 files that I created having just the essentials. The stripped down code worked and let me know that the problem is within my code somewhere.

Thanks for all the input.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.