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

Mary-Kate Olsen
Release: 2024-10-28 12:18:02
Original
978 people have browsed it

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>
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!