Reputation: 63
I'm trying to get the header info of https://universalteambuild.com/ using both php get_headers and CURL but both get timed out.
This is the code I've tried.
<?
// try to get header using get_header
print_r(get_headers("https://universalteambuild.com/"));
// try to get header using CURL
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://universalteambuild.com/');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$a = curl_exec($ch);
echo "$a";
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
?>
To check if the url blocks CURL or header request, I went to https://onlinecurl.com/ and https://www.webconfs.com/http-header-check.php. Both were able to get the header info.
So I'm wondering if the issue is with the configuration of my server.
I would really appreciate if someone can run the script and see if you can get the header info. Thanks.
Upvotes: 1
Views: 3875
Reputation: 11
<?php
################### You can Try this code #######################
$url = "https://universalteambuild.com/";
// try to get header using get_header
echo '<pre>';
echo '++++++++++ get headers using get_headers() method +++++++<br>';
print_r(get_headers($url));
echo '======================================================================<br>';
// try to get header using CURL
echo '++++++++++get headers using Curl+++++++<br>';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
// Then, after your curl_exec call:
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);//get header from curl response
//$body = substr($response, $header_size);
print_r($header);
curl_close($ch);
?>
Upvotes: 0
Reputation: 126
For get_headers() : Check allow_url_fopen is On in php.ini
For curl: Check curl is properly installed and shows as 'enabled' in php.ini
Then restart the server after updating the php.ini
Upvotes: 1
Reputation: 6723
You can try get_headers()
method to retrieve all the headers of an URL.
<?php
$url = "https://universalteambuild.com/";
$headers = get_headers($url);
echo "<pre>";
print_r($headers)
?>
get_headers
— Fetches all the headers sent by the server in response to an HTTP request
Upvotes: 1