To obtain parameters from the URL in PHP, you can use the $_GET super global variable: Make sure the request method is GET. Use the $_GET array to access parameters: keys are parameter names and values are parameter values.
How to get parameters from URL in PHP
In order to get parameters from URL in PHP, you You can use the $_GET
superglobal variable.
Steps:
GET
. You can use $_SERVER['REQUEST_METHOD']
to get the request method. GET
, you can use the $_GET
array to access the parameters in the query string. $_GET
The array is an associative array where the keys are parameter names and the values are parameter values. Example:
The following example demonstrates how to retrieve a file from the URL https://example.com/index.php?name=John&age=30
Get parameters in:
<code class="php"><?php // 检查请求方法 if ($_SERVER['REQUEST_METHOD'] == 'GET') { // 获取参数 $name = $_GET['name']; $age = $_GET['age']; // 输出参数值 echo "姓名:$name" . PHP_EOL; echo "年龄:$age" . PHP_EOL; } ?></code>
Output:
<code>姓名:John 年龄:30</code>
The above is the detailed content of How to get parameters from URL in php. For more information, please follow other related articles on the PHP Chinese website!