Here's how to do this with
cURL[
^]
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
$response = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
$body = substr($response, $header_size);
If you're using php 5.5 or better, you can also use
guzzle; a restful http client for php.[
^]
$client = new GuzzleHttp\Client();
$res = $client->request('GET', 'http://www.example.com/', [
'auth' => ['user', 'pass']
]);
echo $res->getStatusCode();
$header = $res->getHeader('location');
$body = $res->getBody();
and a side note; in PHP,
$myarray[100]='value';
doesn't pre-allocate an array with 100 elements in it. It allocates an array and stores a value in key 100.