Home  >  Article  >  Backend Development  >  Why are My $_POST Values Missing from My PHP Script?

Why are My $_POST Values Missing from My PHP Script?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-10-28 12:18:02979browse

Why are My $_POST Values Missing from My PHP Script?

Missing PHP $_POST Values from php://input

Despite receiving form data through a POST request, certain values fail to appear in the PHP $_POST array. Debugging reveals the presence of these values in the raw request string retrieved via php://input.

Cause:

PHP alters field names containing specific characters (spaces, dots, open square brackets, etc.) to comply with the deprecated register_globals.

Solution:

  • Disable register_globals: Since this setting is deprecated, disable it in the php.ini configuration file.
  • Use a workaround function: Utilize a function that parses the raw request string, extracting and decoding the values to construct a new $vars array containing the missing values. Here's an example:
<code class="php">function getRealPOST() {
    $pairs = explode("&", file_get_contents("php://input"));
    $vars = array();
    foreach ($pairs as $pair) {
        $nv = explode("=", $pair);
        $name = urldecode($nv[0]);
        $value = urldecode($nv[1]);
        $vars[$name] = $value;
    }
    return $vars;
}</code>

The above is the detailed content of Why are My $_POST Values Missing from My PHP Script?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn