当我在我的实际网站上使用函数get_headers($ url)$url = "https://www.example.com/product.php?id=15"
时,它没有从给定的URL返回任何数组。我一无所获。但是当我在localhost上使用相同的代码时,我得到以下信息:
Array
(
[0] => HTTP/1.1 200 OK
[1] => Cache-Control: private
[2] => Content-Type: text/html; charset=utf-8
[3] => Server: Microsoft-IIS/8.5
[4] => Set-Cookie: ASP.NET_SessionId=wumg0dyscw3c4pmaliwehwew; path=/; HttpOnly
[5] => X-AspNetMvc-Version: 4.0
[6] => X-AspNet-Version: 4.0.30319
[7] => X-Powered-By: ASP.NET
[8] => Date: Fri, 18 Aug 2017 13:06:18 GMT
[9] => Connection: close
[10] => Content-Length: 73867
)
那么,为什么该功能在现场无法成功运行?
修改
<?php
if(isset($_POST['prdurl']))
{
$url = $_POST['prdurl'];
print_r(get_headers($url)); // not getting any array on live but on localhost
if(is_array(@get_headers($url)))
{
// some code goes here...
}
else
{
echo "URL doesn't exist!"
}
}
?>
此处需要注意的另一件事是我使用file_get_html
从远程网址检索html网页。它在我的本地主机上工作,但也不在现场工作。