PHP 获取方法

WBOY
发布: 2024-08-29 13:01:56
原创
901 人浏览过

PHP 编程语言的 Get 方法对于从指定/特定资源请求数据非常有帮助。它是从特定资源请求数据的 HTTP 请求方法之一。 HTTP 通常的工作方式就像服务器和客户端之间的请求-响应协议一样。客户端浏览器通常会向特定服务器提交/发送一些 HTTP 请求,但服务器会向客户端返回特定响应。此请求/响应包含有关特定请求的一些状态信息。该请求过程可以来自 PHP 编程语言的 GET 方法。

广告 该类别中的热门课程 PHP 开发人员 - 专业化 | 8 门课程系列 | 3次模拟测试

开始您的免费软件开发课程

网络开发、编程语言、软件测试及其他

语法:

$_GET["name1"]
登录后复制

PHP GET 方法如何工作?

通常,PHP 编程语言的 GET 方法是一种不安全类型的方法,因为它会在 URL 空间/地址栏空间上显示大部分信息。使用 GET 方法仅限于数据发送,但 GET METHOD 有助于快速发送数据。它也是关联数组变量之一,将通过一些 URL 参数传递到当前特定脚本,这些参数只不过是查询字符串。该数组将请求查询字符串。我们可以通过从指定或特定的源/资源请求数据来使 GET 方法在正常的 PHP 程序中工作。

GET 方法还可以通过用户发送一些附加到特定页面请求的编码信息来工作。该页面现在将是由“?”分隔的编码信息。 URL 地址栏空格处的字符。 GET 方法将生成一个非常长的字符串,该字符串出现在特定浏览器的服务器日志中的 location: 框中。发送长度限制为 1024 个字符。如果我们使用 GET 方法传递一些安全信息(例如密码),那么它将被发送到服务器,因此最好不要使用一些重要且安全的信息/信息。 GET 方法不能用于将一些二进制数据(如文字文档、图像等)发送到其自己的服务器/其他服务器。可以借助 GET METHOD 概念发送的 QUERY_STRING 环境变量来访问数据。要访问发送的数据/信息,大多数时候都会使用 $_GET。

在 PHP 中实现 GET 方法的示例

以下是 PHP GET 方法的方法:

示例#1

这是使用 PHP 编程语言的 GET 方法的示例。这里首先使用error_reporting()函数来处理一次错误。然后 x1 和 y1 变量与其中的 GET METHOD f1 和 s1 值一起使用。然后创建 z1 变量来对 x1 和 y1 变量值求和。然后echo语句就是显示z1变量值。然后在表单方法中使用GET方法。表单

内部标签用于创建具有特定列和行的表。传递 f1 和 s1 值以获取 x1 和 y1 变量的信息。然后 z1 变量值将被创建并显示在浏览器结果的顶部。查看输出以了解输入值之前和之后的结果如何。

代码:

<html>
<head>
<title>get_browser1</title>
<?php
error_reporting(1);
$x1=$_GET['f1'];
$y1=$_GET['s1'];
$z1=$x1+$y1;
echo "Sum of the two numbers = ".$z1;
?>
</head>
<body bgcolor="skyblue">
<form method="GET" >
<table border="2" bgcolor="green">
<tr>
<td>Enter the first number for input :: </td>
<td><input type="text" name="f1"/></td>
</tr>
<tr>
<td>Enter the second number for input :: </td>
<td><input type="text" name="s1"/></td>
</tr>
<tr align="center">
<td colspan="3" >
<input type="submit" value="+"/></td>
</tr>
</table>
</form>
</body>
</html>
登录后复制

输出:

1_1:

PHP 获取方法

1_2:

PHP 获取方法

示例#2

在下面的 GET METHOD 概念示例中,用户必须在文本框中输入名称。输入名称并单击“提交输入名称”后即可完成。您将在输入框上方看到输入的名称/单词的输出,然后您将像以前一样再次看到正常的输入框。由于 PHP 编程语言的 GET 方法,用户甚至可以检查 URL 内部的输入。这里首先 echo 语句与 GET METHOD 调用一起使用,但内部的字符串名称/值没有值。因此我们将使用 FORM 方法将值传递给它。然后使用该表以便更好地理解输入输入名称。输入后点击提交按钮,名字就会出现在顶部。

代码:

<html>
<head>
<?php
echo $_GET['n1'];
?>
<title>get_browser2 pavankumar sake</title></head>
<body bgcolor="sky color">
<form method="GET">
<table border="2" bgcolor="green">
<tr>
<td>Enter the name for input :: </td>
<td><input type="text" name="n1"/></td>
</tr>
<tr>
<td colspan="3" align="center">
<input type="submit" value="show the input name"/></td>
</tr>
</table>
</form>
</body>
</html>
登录后复制

输出:

PHP 获取方法

Example #3

This is the example of implementing the GET METHOD to show the name and the age which is entered in the user boxes. Here I entered “pavankumar sake” as name value and “23” as the age value. Here at first, inside of the PHP tags name1 and age1 are used inside, and then using the echo statement they will be printed but those values got from the FORM METHOD below. Check out the output 3_1 and output 3_2 to understand the concept better.

Code:

<?php
if( $_GET['name1'] || $_GET['age1'] ) {
echo "Welcome ". $_GET['name1']. "<br />";
echo "You are ". $_GET['age1']. " years old.";
exit();
}
?>
<html>
<body>
<form action = "<?php $_PHP_SELF ?>" method = "GET">
Name :: <input type = "text" name = "name1" />
Age :: <input type = "text" name = "age1" />
<input type = "submit" />
</form>
</body>
</html>
登录后复制

Output:

3_1:

PHP 获取方法

3_2:

PHP 获取方法

Advantages of PHP GET Method

Since some data which will be sent by the GET METHOD of the PHP language will be displayed in/inside of the specific URL, it will only be possible in order to bookmarking the page which is with the specific query values of the string/strings. The GET METHOD will help the specific method requests can/should be cached and the Get Method requests remains in our browser history. The Get Method requests can/will be bookmarked.

Conclusion

I hope you learnt what is the definition of PHP Get Method along with its syntax and explanation, How the PHP Get Method works along with the various examples and explanation of those examples, Advantages of the Get Method etc. to under the Get Method concept better.

Recommended Article

This is a guide to the PHP GET Method. Here we discuss the introduction, syntax, and working of Get Method in PHP along with examples and advantages. You can also go through our other suggested articles to learn more –

  1. Abstract Class in PHP
  2. Socket Programming in PHP
  3. PHP Frameworks

以上是PHP 获取方法的详细内容。更多信息请关注PHP中文网其他相关文章!

相关标签:
php
来源:php
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!