0

I am trying to get my webhooks header (Woocommerce webhook),

I am retrieving the body with file_get_contents('php://input'), although this only gives the body according to http://php.net/manual/en/wrappers.php.php

I also found this thread: link, but I can't figure it out. Is there any other function that gives me back the header?

My function looks like this:

public function webhook(Request $request) {
    $json = file_get_contents('php://input');
    Storage::disk('local')->put('file.txt', $json);
}

Edit: Other things I tried:

public function webhook(Request $request) {
    $json = file_get_contents('php://input');
    $headers = getallheaders();
    Storage::disk('local')->put('file.txt', $headers['Content-Name']);
}

This sets the webhook to "Disabled", I suppose this throws an error for some reason.

apache_request_headers is not changing the status to "Disabled" but is returning an empty file.txt

ThomasV
  • 346
  • 3
  • 16

3 Answers3

1

Use getallheaders():

This function exists for the sole purpose of retrieving request headers:

$headers = getallheaders();
var_dump($headers['Content-Name']);
Community
  • 1
  • 1
Sapnesh Naik
  • 11,011
  • 7
  • 63
  • 98
  • Thank you, but already tried this. It seems that the codes returns an error because it sets the webhook to disabled after updating the code with it. – ThomasV Feb 26 '18 at 12:56
0

Is there any other function that gives me back the header?

Assuming you use Apache, then: http://php.net/apache-request-headers

Dormilich
  • 927
  • 5
  • 11
0

For the ones who might be facing the same problem in the future, I found the following solution:

public function webhook(Request $request) {
    $json = file_get_contents('php://input');
    Storage::disk('local')->put('file.txt', $json);
    Storage::disk('local')->put('request.txt', Request::header('x-wc-webhook-source'));
}

Main url solution: Link

ThomasV
  • 346
  • 3
  • 16