0

How can I get all headers for domain redirecting to non-ASCII domain?

Related question

The domain www.sendevinci.co.il redirecting to non-ASCII domain www.מגשי-אירוח.co.il.

My code is:

$url = 'http://www.sendevinci.co.il';

$options['http'] = array(
 'method' => "HEAD",
        'ignore_errors' => 1,
        'header' =>
          "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n" .
         "Accept-Language: en-US,en;q=0.8\r\n".
                "Keep-Alive: timeout=3, max=10\r\n",
                "Connection: keep-alive",
 'user_agent' => self::get_user_agent_string($user_agent),
        "timeout" => 3
);

$context = stream_context_create($options);

$body = file_get_contents($url, NULL, $context);

print_r($http_response_header);

The result is:

Array
(
    [0] => HTTP/1.1 301 Moved Permanently
    [1] => Server: nginx
    [2] => Date: Thu, 07 Jun 2018 13:07:30 GMT
    [3] => Content-Type: text/html; charset=UTF-8
    [4] => Connection: close
    [5] => X-Powered-By: PHP/7.2.6
    [6] => Location: https://www.מגשי-אירוח.co.il
    [7] => X-Powered-By: PleskLin
)

The array should include 200 status as well, but it not.

The code works fine for ascii-name domains redirecting to ascii-name domains.

Thanks for you help!

Adam Pery
  • 1,924
  • 22
  • 21

2 Answers2

0

At the HTTP protocol level, a 200 response code with a Location header does not make sense. You can use a Location header with 201 or 202, but generally, 3xx is used for sending the client to a new location. I posit that the response you are receiving is correct. In bullet form, the HTTP location header is valid with:

  • 201 - new resource created; get appropriate new location
  • 202 - request accepted, still processing, check "here"
  • 3xx - general redirection (301/Permanent, 302/Temporary, etc.)

In other words, your assertion that [t]he array should include 200 status as well is not correct. The HTTP status code given by the server in the example is 301.

hunteke
  • 3,648
  • 1
  • 7
  • 17
0

Actually, file_get_contents works ONLY with ascii domain names. So there are no simple solution to get all http headers...

Adam Pery
  • 1,924
  • 22
  • 21