【问题标题】:Errors for changing variables content depending on session status根据会话状态更改变量内容的错误
【发布时间】:2011-07-14 13:46:36
【问题描述】:

我正在尝试编写一个脚本,该脚本根据会话状态和页面 URL 中的 ID(例如 www.example.com/profile.php?id=1)更改验证内容,因此它会如果他们没有登录并查看其他人的个人资料,则显示一组内容,如果已登录并在那里查看自己的个人资料,则显示另一组内容,如果已登录并查看其他人的个人资料,则显示另一组内容。

首先脚本从 url 获取 ID:

if (isset($_GET['id'])) {
     $id = preg_replace('#[^0-9]#i', '', $_GET['id']); // filter everything but numbers
} else if (isset($_SESSION['idx'])) {
     $id = $logOptions_id;
} else {
   header("location: index.php");
   exit();
}

然后它运行一些我不会包含的其他代码,然后是这个代码:

// ------- DECIDES WHAT TO DISOPLAY, DEPENDING ON VERIABLES ---------

if (isset($_SESSION['idx']) && $logOptions_id == $id) { // If session is set and ID matches the profiles ID
$content = ""Your viewing your own profile";

} else if (isset($_SESSION['idx']) && $logOptions_id != $id) { // If SESSION is set, but ID dosent match profiles ID
$follow_option = "Your viewing someone elses profile";


} else {
$content = "Your are not logged in";
}
// ------- END DECIDES WHAT TO DISOPLAY, DEPENDING ON VERIABLES ---------


print $content;

现在我的问题是,它所做的只是显示登录和查看其他人个人资料的选项“您正在查看其他人的个人资料”。如果您发现任何可能导致此问题的错误,请在下面回答。谢谢! :)

【问题讨论】:

    标签: php mysql session variables


    【解决方案1】:

    $logOptions_id != $id 运行时,您的变量没有保持预期值,或者您忘记启动会话。我没有看到分配 $logOptions_id 的参考。使用 IDE 工具调试代码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-03
      • 1970-01-01
      • 2019-10-01
      • 2020-12-06
      • 2013-02-11
      • 2016-04-13
      • 2015-05-16
      相关资源
      最近更新 更多