【问题标题】:Getting a unified $_GET array regardless of how you submit information无论您如何提交信息,都可以获得统一的 $_GET 数组
【发布时间】:2019-06-23 14:46:52
【问题描述】:

所以我将此链接提交到我的 php 代码中:

由于某种原因,我什至不能在下面的 url 中使用 example.com,而只是将目录添加到之前的脚本中。

https://www.example.com/test.php?info1234=3177%3B315961%3B317451%3B315511&info3598=121618%3B136803%3B13830%3B20532

上面的 example.com url 是 1 个 SINGULAR 字符串。用户只提交了一件事情。那一件事恰好是一个包含自己参数的php url。

但是,当我使用表单提交时,我得到了这个$_GET 数组(这是我想要的结果但另一种方式也可以):

Array
(
    [myurl] => https://www.example.com/test.php?info1234=3177;315961;317451;315511
    [info3598] => 121618;136803;13830;20532
)

然后,如果我通过将 myurl 自己放入实际 url 到我自己的程序的 url 中来提交它。如果我输入这个 url,并提交它localhost/test.php?myurl=https://www.example.com/test.php?info1234=3177%3B315961%3B317451%3B315511&info3598=121618%3B136803%3B13830%3B20532,我会得到这个$_GET 数组:

Array
(
    [myurl] => https://www.example.com/test.php?info1234=3177%3B315961%3B317451%3B315511&info3598=121618%3B136803%3B13830%3B20532
)

test.php

<?php
print_r($_GET);

?>

<form action="test.php" method="get">
  myurl: <input type="text" name="myurl"><br>
  <input type="submit" value="Submit">
</form>

【问题讨论】:

    标签: php arrays forms get


    【解决方案1】:

    表单提交 - 提交表单数据。您必须将额外参数添加为隐藏输入。即:

    <input type="hidden" id="info" name="info3595" value="entervaluehereinsuitalbleformat">
    

    【讨论】:

    • 这只是隐藏了输入框,没有修复任何东西,
    • 这个答案是正确的。如果你想要一个info3595 参数,你必须先发送它。下面是一个如何通过 GET w3schools.com/tags/att_form_method.asp 使用表单的示例
    • @RomainB。它只是隐藏了输入框,我不明白它如何解决我的问题。我希望用户能够通过这两件事提交。用户如何将 url example.com url 输入到输入框中?另外我不知道 url 中的信息,所以我不知道 $_GET 中的键名
    • 由于您是通过“get”提交表单,因此您需要在表单中指定所有参数。否则,您可以通过“post”提交表单,在表单的 action 属性中添加完整的 url。
    • &lt;?php print_r($_GET); ?&gt; &lt;form method="post"&gt; myurl: &lt;input type="text" name="myurl"&gt;&lt;br&gt; &lt;input type="submit" value="Submit"&gt; &lt;/form&gt;
    【解决方案2】:

    试试这个:-

    <form action="test.php" method="GET">
    
    myurl: <input type="text" name="myurl"><br>
    
    <input type="hidden" id="info" name="info1234" value="enter_value">
    <input type="submit" value="submit">
    
    </form>
    

    希望有用

    【讨论】:

      猜你喜欢
      • 2017-02-11
      • 1970-01-01
      • 1970-01-01
      • 2016-11-29
      • 1970-01-01
      • 1970-01-01
      • 2017-07-21
      • 2013-08-27
      • 2013-03-03
      相关资源
      最近更新 更多