donglu8334
2017-07-13 01:52
浏览 36
已采纳

获取参数,通过PHP中的链接传递

I get variable from http://localhost/match?id=1 via code:

<?
if (isset($_POST['id'])) {
    $id = $_POST['id'];
    $id = secure($id);
} else {
    echo "error";
    die();
}

And I get the error from my else statement. How to get the parameter, passed via the link?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doujiao6507 2017-07-13 01:54
    已采纳

    Try this code:

    <?
    if (isset($_GET['id'])) {
        $id = $_GET['id'];
        $id = secure($id);
    } else {
        echo "error";
        die();
    }
    

    Params, passed throught the link, are accessable trough the $_GET superglobal.

    Info about $_GET on php.net.

    Some explanations about $_GET vs $_POST on w3schools.com.

    点赞 打赏 评论
  • dongou5100 2017-07-13 01:56

    use POST if you get data from form. and GET if you get data by link. in your case it is link

    if (isset($_POST['id'])) { ** this POST should be GET because you have http://localhost/match?id=1
    
    点赞 打赏 评论

相关推荐 更多相似问题