PHP获取标头不起作用 -

chi*_*ers 3 php

我正在尝试获取URL标头的输出,并且它适用于子域示例

subdomain.example.com
Run Code Online (Sandbox Code Playgroud)

我将获得正常消息HTTP 200 ok等,但如果子域中有-其他内容,则标题中不会显示任何内容.

-test.tumblr.com 要么 test-.tumblr.com

有没有更好的方法呢?我的示例代码如下.

$url = "http://-test.tumblr.com";
$url_headers = @get_headers($url);
$urlheader = $url_headers[0];
echo $urlheader;
Run Code Online (Sandbox Code Playgroud)

如果无法检查标题,我将如何查看页面是否存在.我尝试过使用curl,但它也是如此.

谢谢

Mat*_*att 11

当您取消来自get_headers的警告时,您会收到警告,您只能在网址上使用get_headers吗?

Warning: get_headers(): This function may only be used against URLs
Run Code Online (Sandbox Code Playgroud)

尝试在子域前面添加http://.我在我的hosts文件中添加了一个子域test-.myserver.loc,并且能够获得标题.

$url = 'http://test-.myserver.loc';
print_r(get_headers($url))
Run Code Online (Sandbox Code Playgroud)

http://us3.php.net/get_headers