gpt4 book ai didi

php - get_headers 不一致

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:01:13 24 4
gpt4 key购买 nike

<分区>

运行以下代码

var_dump(get_headers("http://www.domainnnnnnnnnnnnnnnnnnnnnnnnnnnn.com/CraxyFile.jpg"));

对于不存在的任何域或 URL 返回 HTTP 200 而不是 404

Array
(
[0] => HTTP/1.1 200 OK
[1] => Server: nginx/1.1.15
[2] => Date: Mon, 08 Oct 2012 12:29:13 GMT
[3] => Content-Type: text/html; charset=utf-8
[4] => Connection: close
[5] => Set-Cookie: PHPSESSID=3iucojet7bt2peub72rgo0iu21; path=/; HttpOnly
[6] => Expires: Thu, 19 Nov 1981 08:52:00 GMT
[7] => Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
[8] => Pragma: no-cache
[9] => Set-Cookie: bypassStaticCache=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; httponly
[10] => Set-Cookie: bypassStaticCache=deleted; expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/; httponly
[11] => Vary: Accept
)

如果你跑

var_dump(get_headers("http://www.domain.com/CraxyFile.jpg"));

你得到了

Array
(
[0] => HTTP/1.1 404 Not Found
[1] => Date: Mon, 08 Oct 2012 12:32:18 GMT
[2] => Content-Type: text/html
[3] => Content-Length: 8727
[4] => Connection: close
[5] => Server: Apache
[6] => Vary: Accept-Encoding
)

在很多情况下,get_headers 已被证明是验证现有 URL 的解决方案

这是一个 Bug 还是 get_headers 不是验证 URL 的可靠方法

See Live Demo

更新 1

发现CURL也有同样的问题

$curl = curl_init();
curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => true,CURLOPT_URL => 'idontexist.tld'));
curl_exec($curl);
$info = curl_getinfo($curl);
curl_close($curl);
var_dump($info);

Also returns the same result

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com