开发者

Errors for changing variables content depending on session status [duplicate]

This question already has an answer here: Closed 11 years ago.

Possible Duplicate:

Errors for changing vari开发者_StackOverflow社区ables 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! :)


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜