douju6651 2014-12-03 06:55
浏览 36

在PHP中接收查询字符串

I am writing code for a simple WAMP server. It would receive a query string from another machine and simply display the parameters after parsing.

How would the server know that a query string has been received? And when received, how would it perform desired action on the query string?

Edit: The parameters are being passed as URL.

  • 写回答

2条回答 默认 最新

  • duanan5940 2014-12-03 06:58
    关注

    You're looking for the superglobal variable $_GET.

    For example, at the URL http://example.com/foo.php?bar=BAM, the variable $_GET['bar'] has the value BAM.

    You can check whether there are any query string variables by seeing if count($_GET) > 0.

    To check whether a parameter is set, you can do something like this:

    if (isset($_GET['bar'])) {
        // do something cool
    } else {
        echo "Hey, you didn't give me a value for bar!";
    }
    

    Edit: If you are passing it in some other way, not in the URL, then please clarify your question. How you access the data will obviously depend on how you receive it.

    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号