PHP header location 页面跳转的问题

两个相同的的程序 在本地输入用户密码 可以实现跳转,但传到服务器上 就不好好使了 运行到header那 就是跳不过去。求解 代码: if ($_POST["password"] != "111")
{
echo "<script>alert('输入的密码不正确');history.go(-1)</script>";
exit;
}
else
{
session_start();
$_SESSION["login"] = "ok";
print_r($_SESSION);
header('Location:index.php');
// echo "<script>window.parent.location='index.php'</script>";
}
如果用JS跳转的话 是可以实现跳转 但无法通过以下代码判断:session_start();
if($_SESSION["login"] != "ok")
{
echo "<script>alert('请先登录后再使用本程序');parent.location.href='login.php';</script>";
exit;
}
额 print_r($_SESSION);这个 是我忘记删了 跟这个没关系。 我只是调试的时候用的

第1个回答  2011-11-30
虽然你给0分提出这么多麻烦的问题,但还是帮你回答下。在使用session和header之前是不能有输出的,print_r和echo都是用来输出的本回答被提问者采纳
第2个回答  2011-12-14
if ($_POST["password"] != "111")
{
echo "<script>alert('输入的密码不正确');history.go(-1)</script>";
exit;
}
else
{
session_start();
$_SESSION["login"] = "ok";

header('Location:index.php');
// echo "<script>window.parent.location='index.php'</script>";
}

试试本回答被网友采纳
第3个回答  2011-11-30
你要写绝对地址。
相似回答