How to retrieve post request parameters in PHP?
To access POST request parameters, you can use the $_POST array. Here is an example:
<?php
// 判断是否是POST请求
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// 获取POST参数
$username = $_POST['username'];
$password = $_POST['password'];
// 打印输出POST参数
echo "Username: " . $username . "<br>";
echo "Password: " . $password;
}
?>
In the example above, we first determine if the request is a POST request by using $_SERVER[‘REQUEST_METHOD’], then we retrieve the POST parameters using the $_POST array. Finally, we output the retrieved POST parameters.