duanke9540
2011-06-04 17:35
浏览 41
已采纳

PHP会话变量没有注册

I've been searching all day and found several similar issues, but none have resolved my problem. As the title states I'm having trouble with session variables not being "saved" - i.e they work only like local variables. What I'm trying to accomplish:

index page with function "ABC" not running by defualt - link to myscript.php to activate session variable of type boolean - myscript.php checks if session variable is set, if not turns it to true. Otherwise turns it to false: index page should now have function "ABC" activated.

So, here is the funny thing. This worked like a charm earlier today, but after a random refresh, now it don't. Thinking this was a session trouble, I added a session ID but found that the session ID is correct / the same on both the index page and myscript.php.

I've also tried to enable error reporting and found that I'm getting the "Undefined index: showAll in C:\xampp\htdocs\kelvin\ext\set_date.php on line 15". Which is weired, seing as i use the issset function to avoid just that.

myscript.php

<?php
session_start();
echo "Session ID: " . session_id(); //Is the same as on the index page where the script is being called.
---------------
//Sets speed mode on or off (simple or extensive listing).
if(!isset($_SESSION['showAll']))
{    
    $_SESSION['showAll'] == TRUE;
}
 else {
    if($_SESSION['showAll'] == TRUE)
    {
        $_SESSION['showAll'] = FALSE;
    }
    else
    {
        $_SESSION['showAll'] = TRUE;
    }
}
header('location:../index.php');
?>

In advance, thanks for any input :)

图片转代码服务由CSDN问答提供 功能建议

我一整天都在搜索,发现了几个类似的问题,但都没有解决我的问题。 正如标题所述,我遇到的问题是会话变量没有“保存” - 即它们只能像局部变量一样工作。 我正在努力实现的目标:

索引页面,函数“ABC”未运行defualt - 链接到myscript.php以激活boolean - myscript类型的会话变量。 php检查是否设置了会话变量,如果没有,则将其设置为true。 否则将其变为false: index页面现在应该激活“ABC”功能。

所以,这是有趣的事情。 这在今天早些时候就像一个魅力,但在随机刷新之后,现在却没有。 认为这是一个会话故障,我添加了一个会话ID但发现会话ID在索引页面和myscript.php上都是正确/相同的。

我还尝试启用错误报告,发现我在线上获得了“Undefined index:showAll in C:\ xampp \ htdocs \ kelvin \ ext \ set_date.php” 15" 。 我正在使用,因为我使用issset函数来避免这种情况。

myscript.php

 &lt;?php 
session_start(); 
echo“会话ID:”。  SESSION_ID();  //与调用脚本的索引页面相同。
 --------------- 
 //开启或关闭速度模式(简单或扩展列表)  。
if(!isset($ _ SESSION ['showAll']))
 {
 $ _SESSION ['showAll'] == TRUE; 
} 
 else {
 if($ _ SESSION ['showAll']]  == TRUE)
 {
 $ _SESSION ['showAll'] = FALSE; 
} 
其他
 {
 $ _SESSION ['showAll'] = TRUE; 
} 
} 
header('  location:../ index.php'); 
?&gt; 
   
 
 

提前感谢任何输入:)

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanbi8529 2011-06-04 17:39
    已采纳

    Your problem might be here:

    if (!isset($_SESSION['showAll'])) {
      $_SESSION['showAll'] == TRUE;
    }
    

    The double equal sign (==) checks for equality, but does not set anything.

    Try replacing it with the single equal sign (=).


    Also, your logic can be condensed considerably:

    if (!isset($_SESSION['showAll'])) {    
      $_SESSION['showAll'] = true;
    } else {
      $_SESSION['showAll'] = !$_SESSION['showAll'];
    }
    

    You are just swapping the value of $_SESSION['showAll'].

    点赞 打赏 评论

相关推荐 更多相似问题