【问题标题】:I have to face session issue我必须面对会话问题
【发布时间】:2015-12-24 17:02:50
【问题描述】:

我必须在我的新服务器中遇到会话问题。

this link 的会话无法正常工作

我已刷新页面不显示会话,然后再次使用 Ctrl+f5 刷新页面,然后显示会话。

所以请告诉我这是服务器问题还是编码问题??

遇到编码问题而不是解决任何问题。

访问链接查看 phpinfo() :http://brahmanparivar.com/phpinfo.php

index.php 和 display.php

<?php session_start();  ?>
    <html>
       <head>
          <title>PHP session</title>
       </head>
       <body>       
           <? if(isset( $_SESSION['name'] ) ){ 
                echo $_SESSION['name'];
           } else{
           echo "not have a Session";
       } ?>
       <br><br>
    <a href="index.php">home</a> <a href="display.php">display</a> <a href="set.php">set Session</a> <a href="logout.php">Session Out</a>
       </body>
    </html>

logout.php

<?php session_start(); ?>
<html>
<body>
<?php
   if(isset( $_SESSION['name'] ) ){
      session_destroy();
   }else{
       echo "not have a Session";
   }
?>
<br><br>
<a href="index.php">home</a> <a href="display.php">display</a> <a href="set.php">set Session</a> <a href="logout.php">Session Out</a>
</body></html>

set.php

<?php session_start(); 
$_SESSION['name']="Session Set";  ?>
<html>
   <head>
      <title>PHP session</title>
   </head>
   <body>       
       <? if(isset( $_SESSION['name'] ) ){ 
       echo "Set a Session :: Session Set";
   } ?>
   <br><br>
       <a href="index.php">home</a> <a href="display.php">display</a> <a href="set.php">set Session</a> <a href="logout.php">Session Out</a>
   </body>
</html>

【问题讨论】:

  • 向这个问题添加代码并阐明发生了什么以及应该发生什么。
  • 有一个会话问题
  • 代码总是在那里,它只是一个外部链接。我复制了他的代码,并将其放在他的 OP 上,以便更好地提问,以便未来的观众不必使用外部链接。
  • @TareqMahmood 查看他的外部链接中的 URL,以获取“Session Out”链接

标签: php session


【解决方案1】:

在您的 logout.php 页面中,您缺少一个 php 打开标签 &lt;?php

改变这个:

 <? if (isset($_SESSION['name'])) {...

到这里:

<?php if (isset($_SESSION['name'])) {...

【讨论】:

  • 你是对的,但在前面的显示代码中只缺少 html 代码。后端没有缺少php代码。
  • 我不明白你在说什么。
  • 先生,我创建了一个会话,但没有准备好这个会话另一个页面没有刷新(ctrl+f5)。
  • 嗯,是的,您需要刷新页面才能看到它已被销毁。这不会实时发生,因为您需要某种类型的 Web 套接字或 ajax 来检查前端的会话。
【解决方案2】:

我认为短标签不能解决他的问题。当我运行您的代码时,它运行良好。 可能是配置问题。

请阅读:How to get my session to write to apache

看看这是否能解决您的问题,以便进一步排除故障

我想看看 phpinfo();

也附上

<?php 
session_start(); 
echo session_id(); 
?>

到每一页我不认为你的 PHPSESSIONID 没有被设置。正确的

【讨论】:

  • 您对 /tmp/ 的权限是什么?您的用户代理是否有权访问该文件夹?我现在根本无法设置会话。
  • 其实这可能不是它与 curl 工作正常
  • curl -c a http://brahmanparivar.com/session/set.php curl -b a http://brahmanparivar.com/session/index.php curl -b a http://brahmanparivar.com/session/display.php
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-06-17
  • 2011-06-07
  • 2011-12-28
  • 2011-01-25
  • 1970-01-01
  • 1970-01-01
  • 2020-08-28
相关资源
最近更新 更多