即使网站不存在,我也总是得到 301 HTTP 标头代码 (PHP)



我试图弄清楚Instagram用户是否存在。如果用户站点不存在,它应该在标题中给我一个"404 未找到",但我总是得到一个"301 永久移动",即使用户不存在! 我的浏览器给了我一个404: https://i.stack.imgur.com/4LUFK.png 你能帮我吗?这是我的代码:

<?php 
$url = "https://www.instagram.com/asdsdfsvxd"; //This user doesn't exist
echo $url;
$file_headers = @get_headers($url);
echo $file_headers[0];
if($file_headers[0] !== 'HTTP/1.1 404 Not Found') {
echo "exists";
} else {
echo "not exists";
}
?>

解决方案:

不要忘记尾随/(斜杠(。

$url = "https://www.instagram.com/asdsdfsvxd/";

输出:

$ php test.php
https://www.instagram.com/asdsdfsvxd/HTTP/1.1 404 Not Foundnot exists

最新更新