【发布时间】: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