我有一个index.php用于注册,一个login.php作为注册处理程序。当注册失败时,它会向客户端发送错误消息。我使用此代码发送消息
header('Location: http://localhost/musicshare/index.php?reg=false');
并在index.php中接收
if(isset($_POST['reg'])){
echo 'set';//for checking whether reg is set
if($_POST['reg']=='false'){
echo '<script type="text/javascript">';
echo 'alert("Reg faile")';
echo '</script>';
}
}
然而,它似乎根本不起作用;请帮助,谢谢。
答案 0 :(得分:1)
使用$_GET
代替$_POST
:
if (isset($_GET['reg']) && $_GET['reg'] == 'false'){
// do something
}
答案 1 :(得分:0)
当您使用标头()时,它会触发GET
请求。
所以你应该使用$ _GET [&#39; reg&#39;]
if(isset($_GET['reg'])){
echo 'set';//for checking whether reg is set
if($_GET['reg']=='false'){
echo '<script type="text/javascript">';
echo 'alert("Reg faile")';
echo '</script>';
}
}