【发布时间】:2015-04-05 09:16:29
【问题描述】:
如果 cookie 不等于变量,我正在努力重定向用户。如果它确实等于变量,那么它应该继续脚本。这是我的重定向代码:
if(empty($_GET)) {
//No variables are specified in the URL.
//Do stuff accordingly
echo "No variables specified in URL...";
} else {
//Variables are present. Do stuff:
$id = htmlspecialchars($_GET["id"]);
echo 'url query is ' . $id;
}
if(isset($_COOKIE['logged_in']) == $id)
{
header("Location: test.php");
}
if(isset($_COOKIE['logged_in']) != $id)
{
//continues the script
请注意 if 语句中的变量 ($id) 是来自 url 查询的变量;例如,如果 url 是“random.com/test.php?id=17”并且 cookie 等于 18,则脚本应该重定向。但是,如果 url 是“random.com/test.php?id=17”并且 cookie 等于 17,则留在同一页面上。对不起,如果听起来很复杂。
它不像这段代码那样工作:无论变量等于什么,它都不会重定向。谢谢
【问题讨论】:
-
你能解释一下吗?
"random.com/test.php?id=17" and the cookie equals 18 the script should redirect当你的脚本说如果相等它应该重定向。你能复习一下你的问题吗?