dongxiang5879 2011-03-14 08:00
浏览 34
已采纳

根据会话状态更改变量内容的错误[重复]

Possible Duplicate:
Errors for changing variables content depending on session status

Hello! I am trying to write a script that changes a veriables content depending on there session status and what ID that was in the URL of the page (e.g www.example.com/profile.php?id=1) so it would display one set of content if they arnt logged in and viewing someone elses profile, another if there logged in and on there own profile, and another if there logged in and viewing someone elses profile.

Firstly the script gets the ID from the url:

 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();
}

Then it runs some other code i wont include, then this code:

// ------- DECIDES WHAT TO DISPLAY, DEPENDING ON SESSION---------

    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 DISPLAY, DEPENDING ON SESSION---------

print $content;

Now to my problem, all it does is display the option for being logged in and viewing someone elses profile "Your viewing someone elses profile". If you see any errors that would lead to this, please answer below. Thanks! :)

  • 写回答

1条回答 默认 最新

  • duanhuayong6687 2011-03-14 08:20
    关注

    From what I can see, there are no errors. The id just doesn't match logoptions.

    Most likely, you are changing the id or logoptions somewhere between tha assignment and the final check. Try a vardump in both locations on both variables to see if they still match.

    Btw, you can use intval() or simply cast as (int) instead of the regex

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog