Sending Custom Header with CURL
If you need to get and set custom http headers in php, the following short tutorial is really useful:
Sending The Request Header
$uri = 'http://localhost/http.php';$ch = curl_init($uri);curl_setopt_array($ch, array( CURLOPT_HTTPHEADER => array('X-User: admin', 'X-Authorization: 123456'), CURLOPT_RETURNTRANSFER =>true, CURLOPT_VERBOSE => 1));$out = curl_exec($ch);curl_close($ch);// echo response outputecho $out;
Reading the custom header
print_r(apache_request_headers());
you should see
Array( [Host] => localhost [Accept] => */* [X-User] => admin [X-Authorization] => 123456 [Content-Length] => 9 [Content-Type] => application/x-www-form-urlencoded)
Custom Headers with PHP CGI
in .htaccess
RewriteEngine OnRewriteRule .? - [E=User:%{HTTP:X-User}, E=Authorization:%{HTTP:X-Authorization}]
Reading the custom headers from $_SERVER
echo $_SERVER['User']; echo $_SERVER['Authorization'];
Resources