Get php virtual () response headers

Below is the subquery and its HTTP response content is displayed:

<?php 
if (condition()) {
    virtual('/vh/test.php');
}
?>

Is there any way to get response headers?

My goal is to redirect my request (with request headers) to another location on another host that is executed using the Apache ProxyPass directive, and set its response (headers and contents) as the response to my request.

So, my server will act as a reverse proxy. But he will check some condition that requires the execution of php context before sending the request.

+4
source share
2 answers

, original. virtual(), apache , virtual. ( apache_response_headers()) array_diff():

<?php
$original   = apache_response_headers();

virtual('somepage.php');

$virtual    = apache_response_headers();
$difference = array_diff($virtual, $original);

print_r($difference);
?>

- this:

, , .

, . cURL:

<?php
header('Content-Type: text/plain; charset=utf-8');

$cUrl = curl_init();

curl_setopt($cUrl, CURLOPT_URL, "http://somewhere/somepage.php");
curl_setopt($cUrl, CURLOPT_HEADER, true);
curl_setopt($cUrl, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($cUrl);
curl_close($cUrl); 

print_r($response);
?>
+3

All Articles