admin 发表于 2023-2-16 18:54:42

PHP $_GET 变量

<div id="article_content" class="article_content clearfix">
      <link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/kdoc_html_views-1a98987dfd.css">
      <link rel="stylesheet" href="https://csdnimg.cn/release/blogv2/dist/mdeditor/css/editerView/ck_htmledit_views-6e43165c0a.css">
                <div id="content_views" class="htmledit_views">
                  <h2>$_GET 变量</h2>
<p>预定义的 $_GET 变量用于收集来自 method&#61;&#34;get&#34; 的表单中的值。</p>
<p>从带有 GET 方法的表单发送的信息&#xff0c;对任何人都是可见的&#xff08;会显示在浏览器的地址栏&#xff09;&#xff0c;并且对发送信息的量也有限制。</p>
<h3>实例</h3>
<p>form.html 文件代码如下&#xff1a;</p>
<pre><html>
<head>
<meta charset&#61;&#34;utf-8&#34;>
<title>菜鸟教程(runoob.com)</title>
</head>
<body>

<form action&#61;&#34;welcome.php&#34; method&#61;&#34;get&#34;>
名字: <input type&#61;&#34;text&#34; name&#61;&#34;fname&#34;>
年龄: <input type&#61;&#34;text&#34; name&#61;&#34;age&#34;>
<input type&#61;&#34;submit&#34; value&#61;&#34;提交&#34;>
</form>

</body>
</html></pre>
<p>当用户点击 &#34;Submit&#34; 按钮时&#xff0c;发送到服务器的 URL 如下所示&#xff1a;</p>
<pre>http://www.runoob.com/welcome.php?fname&#61;Runoob&age&#61;3</pre>
<p>&#34;welcome.php&#34; 文件现在可以通过 $_GET 变量来收集表单数据了&#xff08;请注意&#xff0c;表单域的名称会自动成为 $_GET 数组中的键&#xff09;&#xff1a;</p>
<pre>欢迎 <?php echo $_GET[&#34;fname&#34;]; ?>!<br>
你的年龄是 <?php echo $_GET[&#34;age&#34;]; ?>岁。</pre>
<p>以上表单执行演示&#xff1a;</p>
<p style="text-align:center;"></p>
<hr>
<h2>何时使用 method&#61;&#34;get&#34;&#xff1f;</h2>
<p>在 HTML 表单中使用 method&#61;&#34;get&#34; 时&#xff0c;所有的变量名和值都会显示在 URL 中。</p>
<p><strong>注释&#xff1a;</strong>所以在发送密码或其他敏感信息时&#xff0c;不应该使用这个方法&#xff01;</p>
<p>然而&#xff0c;正因为变量显示在 URL 中&#xff0c;因此可以在收藏夹中收藏该页面。在某些情况下&#xff0c;这是很有用的。</p>
<p><strong>注释&#xff1a;</strong>HTTP GET 方法不适合大型的变量值。它的值是不能超过 2000 个字符的。</p>
<p></p>
                </div>
      </div>
      <div id="treeSkill"></div>
页: [1]
查看完整版本: PHP $_GET 变量