2


I want to get headers of website but get_headers return nothing
This is my code

<?php
$url = 'http://www.example.com';

print_r(get_headers($url));
?>

For your information my web hosting provider is network solution
Does the problem from my code or from the web hosting provider ?
And what's the solution to get the headers of one website ?

user3609057
  • 31
  • 1
  • 3
  • 6
  • 1
    It can be disabled on the server. Can you put on error_reporting and see if you get any warnings? – Stefan May 24 '14 at 11:54

1 Answers1

6

If get_headers is disabled then you can also use cURL instead.

$curl = curl_init();
curl_setopt_array($curl, array(    
    CURLOPT_URL => $url,
    CURLOPT_HEADER => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_NOBODY => true));

$header = explode("\n", curl_exec($curl));
curl_close($curl);

print_r($header);
Stefan
  • 1,248
  • 6
  • 23
  • it's working but i want receive `[Server] => Apache/1.3.27 (Unix) (Red-Hat/Linux)` like this because i want to know the OS of the server – user3609057 May 24 '14 at 12:03
  • @user3609057 you do know that some servers block this kind of information for security reasons, right? – Nikita 웃 May 24 '14 at 12:06
  • @CreativeMind yes of course but before on same website i get headers but when i changed to network solution it just stop :/ any solution ? – user3609057 May 24 '14 at 12:09
  • @CreativeMind ah yeah the problem was from the website any way thank you Best Answer – user3609057 May 24 '14 at 12:10
  • @user3609057 before you try any programmatic way, first check if the server you are testing this on gives this info at all, by using tools like: https://addons.mozilla.org/en-US/firefox/addon/live-http-headers/ for Firefox – Nikita 웃 May 24 '14 at 12:10
  • but what if there is no cURL? Like in PHP4 – GeneCode Oct 03 '18 at 07:25