Jump to content

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


mmtalon

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>';
?>
Link to comment
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>';
?>
Link to comment
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.
Link to comment
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.
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.