I can't read my POST HTTP request's body with PHP !

前端 未结 3 1283
青春惊慌失措
青春惊慌失措 2020-12-06 16:40

I\'ve never used PHP but right now, I need to write a PHP file that displays in a log file the content of the body of a POST HTTP request.

I\'ve read that you can ac

相关标签:
3条回答
  • 2020-12-06 17:12

    The global variable is $_POST, not _POST. Also it might be that you are sending the data via GET method, in which case you need to use the $_GET global variable.

    If you want to check for either POST or GET method, you can use the global variable $_REQUEST. Sample code bellow:

    <html>
    <body>
    <form method="POST" action="postdata.php">
    <input type="text" name="mydata" />
    <input type="submit">
    </form>
    </body>
    </html>
    

    file postdata.php:

    <?php
    
    $result = $_POST['mydata'];
    echo $result;
    
    0 讨论(0)
  • 2020-12-06 17:31
    $post_body = file_get_contents('php://input');
    

    php://input allows you to read raw POST data. It is a less memory intensive alternative to $HTTP_RAW_POST_DATA and does not need any special php.ini directives. php://input is not available with enctype="multipart/form-data".

    (Source: http://php.net/wrappers.php)

    0 讨论(0)
  • 2020-12-06 17:32

    Maybe you misspelled it. The array's correct name $_POST.

    Try this

    <?php
    var_dump($_POST);
    

    and see what happens.

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