php $_POST array empty upon form submission

前端 未结 27 2647

I have a custom CMS i\'ve built that works perfectly on my dev box (Ubuntu/PHP5+/MySQL5+).

I just moved it up to the production box for my client and now all form su

相关标签:
27条回答
  • 2020-11-22 09:43

    I know this question was about POST via a Form, but came here looking for answers for similar issue when POSTing with JSON content-type. Found the answer and wanted to share it as it cost me much time.

    When using JSON content-type the $_POST array will not populate (only with multi-part forms I believe)

    Here is what did work to correct the issue:

    $rest_json = file_get_contents("php://input");
    $_POST = json_decode($rest_json, true);
    

    hope this helps someone!

    0 讨论(0)
  • 2020-11-22 09:44

    same issue here!

    i was trying to connect to my local server code via post request in postman, and this problem wasted my time alot!

    for anyone who uses local project (e.g. postman): use your IPv4 address (type ipconfig in cmd) instead of the "localhost" keyword. in my case:

    before:

    localhost/app/login
    

    after:

    192.168.1.101/app/login
    
    0 讨论(0)
  • 2020-11-22 09:44

    In addition to MRMage's post:

    I had to set this variable to solve the problem that some $_POST variables (with an large array > 1000 items) disappeared:

    suhosin.request.max_vars = 2500
    

    "request", not "post" was the solution...

    0 讨论(0)
  • 2020-11-22 09:45

    I came across a similar yet slightly different issue and it took 2 days to understand the issue.

    • In my case also POST array was empty.

    • Then checked with file_get_contents('php://input'); and that was also empty.

    Later I found that browser wasnt asking confirmation for resubmitting form data after If I refresh the page loaded after POST submission. It was directly refreshing page. But when I changed form URL to a different one it was passing POST properly and asked for resubmitting data when attempted to refresh page.

    Then I checked what is wrong with actual URL . There were no fault with URL, however it was pointing to a folder without index.php in URL and I was checking POST at index.php.

    Here I doubted the redirection from / to /index.php causes POST data to be lost and tested URL with appending index.php to the URL.

    That Worked.

    Posted it here so someone would find it helpful.

    0 讨论(0)
  • 2020-11-22 09:45

    I could solve the problem using enctype="application/x-www-form-urlencoded" as the default is "text/plain". When you check in $DATA the seperator is a space for "text/plain" and a special character for the "urlencoded".

    Kind regards Frank

    0 讨论(0)
  • 2020-11-22 09:45

    Make sure you use name="your_variable_name" in input tag.

    I mistakenly use id="your_variable_name".

    I spent much time to catch the bug.

    0 讨论(0)
提交回复
热议问题