提交之前,$\u服务器中出现了GET方法 获取值在URL中发送,在HTTP正文中发布。所以“获取”值也可以完成,但可能是空的。帖子必须手动创建。但是,如果您想在本例中使用GET。保卫它: <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" onsubmit="return checkValid(this)" method="GET"> <input type="text" name="Symbol"> <input type="submit" name="submit" value="Search"> </form> <?php if($_SERVER["REQUEST_METHOD"] == "GET"){ echo "test"; $CSymbol = $_GET["Symbol"];} ?>

提交之前,$\u服务器中出现了GET方法 获取值在URL中发送,在HTTP正文中发布。所以“获取”值也可以完成,但可能是空的。帖子必须手动创建。但是,如果您想在本例中使用GET。保卫它: <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" onsubmit="return checkValid(this)" method="GET"> <input type="text" name="Symbol"> <input type="submit" name="submit" value="Search"> </form> <?php if($_SERVER["REQUEST_METHOD"] == "GET"){ echo "test"; $CSymbol = $_GET["Symbol"];} ?>,php,get,Php,Get,GET和POST是两种不同类型的HTTP请求 根据维基百科: <?php if($_SERVER["REQUEST_METHOD"] == "GET" && isset($_GET["Symbol"]){ echo "test"; $CSymbol = $_GET["Symbol"];} ?> 及 因此本质上,GET用于检索远程数据,POST用于插入/更新远程数据 POST submits data to be processed (e.g., fr

GET
POST
是两种不同类型的HTTP请求

根据维基百科:

<?php
if($_SERVER["REQUEST_METHOD"] == "GET" && isset($_GET["Symbol"]){
    echo "test";
    $CSymbol = $_GET["Symbol"];}
?>

因此本质上,
GET
用于检索远程数据,
POST
用于插入/更新远程数据

POST submits data to be processed (e.g., from an HTML form) to the identified
resource. The data is included in the body of the request. This may result in
the creation of a new resource or the updates of existing resources or both.
最后,在对
AJAX
请求使用
GET
时,一个重要的考虑因素是一些浏览器(尤其是IE)将缓存GET请求的结果。因此,例如,如果您使用相同的
GET
请求进行轮询,您将始终返回相同的结果,即使您查询的数据正在服务器端更新。缓解此问题的一种方法是通过附加
时间戳
使每个请求的URL唯一

对于您的上述代码

Authors of services which use the HTTP protocol SHOULD NOT use GET based forms 
for the submission of sensitive data, because this will cause this data to be 
encoded in the Request-URI. Many existing servers, proxies, and user agents will
log the request URI in some place where it might be visible to third parties.
Servers can use POST-based form submission instead

每个非POST的http请求都算作GET请求,因此每个加载的页面都有一个空GET请求,php将为每个非POST请求创建一个超级全局$\u GET数组


希望这有助于您了解发生了什么。

GET搜索url帖子从输入框中获取数据。
Authors of services which use the HTTP protocol SHOULD NOT use GET based forms 
for the submission of sensitive data, because this will cause this data to be 
encoded in the Request-URI. Many existing servers, proxies, and user agents will
log the request URI in some place where it might be visible to third parties.
Servers can use POST-based form submission instead
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" onsubmit="return checkValid(this)" method="GET">
    <input type="text" name="Symbol">
    <input type="submit" name="submit" value="Search">
</form>
<?php
if($_SERVER["REQUEST_METHOD"] == "GET" && !empty($_GET['Symbol'])){
    echo "test";
    $CSymbol = $_GET["Symbol"];}
?>