url中的PHP头传递参数
我有一个index.php用于注册,一个login.php作为注册处理程序。当注册失败时,它向客户端发送错误消息。我用这个代码发送信息url中的PHP头传递参数,php,header,http-headers,Php,Header,Http Headers,我有一个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[
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>';
}
}
if(isset($\u POST['reg'])){
echo“set”;//用于检查是否设置了reg
如果($_POST['reg']=='false'){
回声';
回显“警报”(“Reg故障”);
回声';
}
}
然而,它似乎根本不起作用;请帮助,谢谢。使用
$\u GET
而不是$\u POST
:
if (isset($_GET['reg']) && $_GET['reg'] == 'false'){
// do something
}
当您使用header()时,它会触发一个GET
请求
所以您应该使用$\u GET['reg']
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>';
}
}
if(isset($\u GET['reg'])){
echo“set”;//用于检查是否设置了reg
如果($\u GET['reg']=='false'){
回声';
回显“警报”(“Reg故障”);
回声';
}
}
如果您的问题得到了回答,请接受合适的答案。