Skip to content
Advertisement

XMLHttpRequest Send converted to PHP file_get_contents

So I’m trying to get the send data in an XHR to be put into the header in PHP’s file_get_contents.

Because I need the exact Referer header when sending the post request, I need to do it PHP file_get_contents with stream_context_create style.

I basically need this:

JavaScript

turned into PHP, like this:

JavaScript

I do know that the X-Requested-With: XMLHttpRequest part is correct, but I don’t have a remote clue what the specific header value I could put in the $opts variable that could replace the xhr.send() function/just send the JSON data.

Advertisement

Answer

I don’t think xhr will allow you to set the Referer header it is set automatically.
On the server side you should be able to, see below.

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement