0

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 ?

3
  • PHP header function sets response header which apache returns to clients. Headers in the question are request headers sent to apache by clients. Commented Sep 13, 2016 at 7:33
  • ok what about just address and referer and cookies and params in one command ? Commented Sep 13, 2016 at 7:36
  • You cannot set referer or make browser submit a POST request via headers. Please see my answer for details. Commented Sep 13, 2016 at 7:56

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

PHP header function sets response header which apache returns to clients. Headers in the question are request headers sent to apache by clients.

From the HTTP/1.1 specification:

6.2 Response Header Fields

The response-header fields allow the server to pass additional information about the response which cannot be placed in the Status- Line. These header fields give information about the server and about further access to the resource identified by the Request-URI.

   response-header = Accept-Ranges           ; Section 14.5
                   | Age                     ; Section 14.6
                   | ETag                    ; Section 14.19
                   | Location                ; Section 14.30
                   | Proxy-Authenticate      ; Section 14.33
                   | Retry-After             ; Section 14.37
                   | Server                  ; Section 14.38
                   | Vary                    ; Section 14.44
                   | WWW-Authenticate        ; Section 14.47

Response-header field names can be extended reliably only in combination with a change in the protocol version. However, new or experimental header fields MAY be given the semantics of response- header fields if all parties in the communication recognize them to be response-header fields. Unrecognized header fields are treated as entity-header fields.

Other RFCs extend this list, but you cannot set referrer, or make browser to submit another POST request via headers.

2 Comments

So in this case with apache header we can just call one url without any referer ? if yes, how we can call that ?
I believe you are falling into XY problem. I suggest to delete the question and ask the real one - what you are trying to achieve.
-1

You can send multiple headers one by one using the optional "replace" argument and setting it to false. So, for example, you could send

header("http://example.com/test.php");
header("POST test.php HTTP/1.1",false);

and so on. This would append to the original header.

Source : http://php.net/manual/en/function.header.php

2 Comments

I know that ,as I told in my question, but it's about 1000 files ! and I want to send all in one command
The replace is used to replace a header you have already set using the header() function... It is not to reset different header types....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.