Sam Sam - 2 months ago 12
Apache Configuration Question

How to send apache headers via php like this method ?

I've an app that generates several apache raw file like below how can I use all of that as request to php ? as I know we can call them separately like

header("Location: http://www.example.com/");
but how we can call all of them from one command like this ? (it's just for example)

<?php
header("http://example.com/test.php

POST test.php HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:48.0) Gecko/20100101 Firefox/48.0
Accept: application/json, text/javascript, */*; q=0.01
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://example.com/test/
Content-Length: 87
Cookie: __cfduid=somevalue;
Connection: keep-alive
a=1&b=2");
?>


I want to send it completely to my server is it possible ?

Answer

You could extract it from a text and use the header() method after all... Sort of like this:

<?php
$txt = "http://example.com/test.php
POST test.php HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:48.0) Gecko/20100101 Firefox/48.0
Accept: application/json, text/javascript, */*; q=0.01
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://example.com/test/
Content-Length: 87
Cookie: __cfduid=somevalue;
Connection: keep-alive
a=1&b=2";

array_map("header", explode("\n", $txt));

So essentially, every new line creates an entry in an array. array_map() traverses the array and for every item in the array, the header() function is invoked with the item in the array as sole argument.

Comments