简体   繁体   English

会话没有显示,但肯定存在,如下页所示

[英]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 (ie it prints "array()" ). 当代码调用会话时,页面只显示“1”,然后显示一个空数组(即打印“array()”)。

Then when clicking on the link to "auto-monthly-refills-form.php" it displays all the sessions! 然后当点击“auto-monthly-refills-form.php”链接时,它会显示所有会话! The "auto-monthly-refills-form.php" file looks simply like this: "auto-monthly-refills-form.php"文件看起来像这样:

<?
  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! 即使删除了两个页面上的session_start(),它仍然可以正常工作! How could this be? 怎么会这样?

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) (我原本以为每个页面都需要它自己的session_start()但是由于某种原因它们没有,而且所有这些都显然是基于一页...有点复杂的解释 - 足以说我想要解决别人的代码:-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. 无论如何,我查看了连接到这个文件的所有文件,除了主要的文件之外,还删除了所有的session_start() 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? 为什么会有太多session_starts()导致问题?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM