【问题标题】:PHP header pass parameters in urlurl中的PHP标头传递参数
【发布时间】:2012-06-15 06:06:08
【问题描述】:

我有一个 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>';
        }
    }

但是,它似乎根本不起作用;请帮忙,谢谢。

【问题讨论】:

  • 如果您的问题得到解答,请接受您合适的答案。

标签: php header http-headers


【解决方案1】:

使用$_GET 代替$_POST

if (isset($_GET['reg']) && $_GET['reg'] == 'false'){
   // do something
}

【讨论】:

    【解决方案2】:

    当您使用 header() 时,它会触发 GET 请求。

    所以你应该使用 $_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>';
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-11
      相关资源
      最近更新 更多