PHP get_headers不工作?

问题描述:



我想获取网站标题,但get_headers不返回任何内容

这是我的代码


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 ?

如果禁用了get_headers,那么你也可以使用cURL。

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);