0

I created an API using cakephp but when I use get or post for example I got the right result with this message:

Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in Unknown on line 0

Warning: Cannot modify header information - headers already sent in Unknown on line 0

This is my php fuction:

public function token()
{
    $user = $this->Auth->identify();
    if (!$user) {
        throw new UnauthorizedException('Invalid Password or email');
    }

    $this->set([
        'success' => true,
        'data' => [
            'token' => JWT::encode([
                'sub' => $user['id'],
                'exp' =>  time() + 604800
            ],
            Security::salt())
        ],
        '_serialize' => ['success', 'data']
    ]);
}

How can I fix this?

Community
  • 1
  • 1
  • 3
    Why not show your script where this is occurring. Also, if you look at the manual it states this: *In general, php://input should be used instead of $HTTP_RAW_POST_DATA* – Rasclatt Jun 10 '16 at 04:19
  • @Rasclatt here is my function and sorry I'm a beginner with cakephp and php so I have no idea about this warning. I just followed this [tutorial](http://www.bravo-kernel.com/2015/04/how-to-add-jwt-authentication-to-a-cakephp-3-rest-api/) –  Jun 10 '16 at 04:25
  • HTTP Headers already sent, is an indication, that some "output" of your php script was sent to client, that forced the pipeline to assemble header lines, send them (at least to a buffer, appended content, so that it is now too late to change header lines). Check [How to fix “Headers already sent” error in PHP](http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) for ideas on how to find this. – Dilettant Jun 10 '16 at 04:31
  • @Dilettant thanks for your answer . I tried the link you sent me without result. Sorry I'm not good with php so if there is a solution it will be helpful for me to be with steps –  Jun 10 '16 at 06:43
  • The hint on the header dilemma missing a line number indicates that included stuff like cakephp may cause such ourput on error/warning. Maybe try silenc all warning messages in your master script/php config and test if the header warning goes away. Than you know better where to continue changing. Maybe try fresh version of cakephp? – Dilettant Jun 10 '16 at 06:47
  • First I'm using the last version of cakephp and second I tried to turn off all the warnings and the error but i still have the same problem –  Jun 10 '16 at 06:55
  • 2
    CakePHP has no references to HTTP_RAW_POST_DATA afair - you need to look for and show the code responsible for that. – AD7six Jun 10 '16 at 07:09

2 Answers2

0

You need to change the php.ini setting for 'always_populate_raw_post_data' to -1.

Nick Zinger
  • 1,174
  • 1
  • 12
  • 28
0

OK I found a solution but I didn't understand how it works

Using Postman if I insert data via RAW in body I got that warning message but I tried to insert data via x-www-form-urlencoded and it works fine . I got json response without HTML. Any explication for that ?