Ad

Getting Header Info Through Php://input

- 1 answer

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

Ad

Answer

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

Ad
source: stackoverflow.com
Ad