Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sessions not showing but are definitely there as shown from next page

Baffling!
I have a page that should have some sessions stored, yet when I try to print them nothing shows up.
There must be sessions there because this first page has a link that takes me to a second page and in that second page I can successfully display the sessions!

<? 
  session_start(); 
  include "frontend/header.php";
?>
</head>

<body>
  <div id="header">
        <? include "frontend/menu.php";?>
        <div class="clear"></div>
  </div>
  <div id="green_bg" style="display:block">

<?
  echo "1";
  echo "<pre>";print_r($_SESSION); echo"</pre>";
?>

<div class="main thank-you">
<a class="thank_you">Thank You</a>
<p>Your phone number will be refilled in a moment. <br/>
  Please check your emails for confirmation.
</p>

<div class="signUp4MonthlyRefills" style="background-color: #f7931e; padding: 20px;">

  <h3>Do you want to save time and effort?</h3>
  <br/>
  Then leave the refills to us!! 
  <br/>
  <br/><i>Introducing</i>... Auto Monthly Refills!!
  <p>Sign up for automatic monthly refills and you'll never have to worry about your phone running out of credit! 

    <h1 align="center"><a href="auto-monthly-refills-form.php" style="font-size: 30px">Click Here To Sign Up.</a></h1></p>
   </div>
<br />

</div>
</div>
<? include "frontend/footer.php";?>

When the code calls for the sessions, the page just displays '1' and then an empty array (i.e. it prints "array()" ).

Then when clicking on the link to "auto-monthly-refills-form.php" it displays all the sessions! The "auto-monthly-refills-form.php" file looks simply like this:

<?
  session_start();
  echo "<pre>";print_r($_SESSION); die();

And the sessions are now displayed (a lot of data)!!
If anyone has any ideas what might be the issue...

UPDATE:
Even after deleting the session_start() on both pages it still works as normal! How could this be?

like image 834
Ben Avatar asked May 01 '16 13:05

Ben


1 Answers

Okay... Sorted it out... Please read...

Even though this is a new page, the code is sort of coming off layers of other files...

I didn't think this should have been an issue...

(I had thought that each page needed it's own session_start() but for some reason they don't and all of them apparently are based off one page... bit complicated to explain - suffice it to say that I am trying to sort out someone else's code :-P)

Anyway, I went through all the files that are connected to this one, deleted all the session_start()s from them besides for the primary one. Now it's working fine.

The data now displays perfectly!

Question:
Does anyone have an explanation for this?
Why does having too many session_starts() cause problems?

like image 150
Ben Avatar answered Nov 15 '22 14:11

Ben