Php 从uri获取并重定向到url
我想在登录后重定向到uri中的url。我现在的代码是:Php 从uri获取并重定向到url,php,redirect,Php,Redirect,我想在登录后重定向到uri中的url。我现在的代码是: if ( $count == 1 && $row['userPass']==$password && $row['online']=="N") { $_SESSION['user'] = $row['userID']; mysql_query("UPDATE users SET online='Y' WHERE userID=".$_SESSION['user']); if (isse
if ( $count == 1 && $row['userPass']==$password && $row['online']=="N") {
$_SESSION['user'] = $row['userID'];
mysql_query("UPDATE users SET online='Y' WHERE userID=".$_SESSION['user']);
if (isset($_GET['url'])) {
$back==$_GET['url'];
header("Location: ".$back);
exit;
} else {
header("Location: /subdom/demo/");
exit;
}
}
但是它重定向到主页面,而不是uri中的页面。URL类似于localhost/subdom/demo/login.php?URL=/subdom/demo/mixy.php。为什么不工作?您看到语法错误了吗
header("Location: $_GET['url]");
换成这个
header("Location: ". $_GET['url']);
试试这个
if (!empty(@$_GET['url'])) {
header("Location: " . $_GET['url]);
exit;
} else {
header("Location: /subdom/demo/");
exit;
}
}
Mysql库已弃用请参见,并且您的代码易受SQL注入攻击,请改用。另外,允许“打开重定向”是一种不好的做法,即重定向到URL中指定的URL。您至少应该验证您重定向到的URL是否为相对URL(即您主页的一部分)@giraff我该怎么做?它不工作,那么怎么做呢?在发送标题之前,您是否输出了一些内容(即使只有1个空格)?有PHP函数
headers\u sent()
来检查这一点。如果你不能避免这种情况,你需要改为通过Javascript重定向。我想我在它之前没有输出任何东西,但我会在家里检查它为什么不使用isset?不是一样吗?isset检查变量是否存在。空的已验证它是否为空。。。对你有用吗?如果有效,请选择最佳答案。。。