【发布时间】:2020-01-02 21:03:17
【问题描述】:
我正在尝试检测 php 中的错误 403。当我从 URL 加载内容并且出现错误 403 时,显示其他内容。使用 404 可以,但是使用 403 则不起作用。我有 2 个网址链接: 1)404:https://images-na.ssl-images-amazon.com/images/M/MV5BMTUwODE3MDE0MV5BMl5BanBnXkFtZTgwNTk1MjI4MzE@._V1_SX300.jpg; 2)403:http://ia.media-imdb.com/images/M/MV5BMTg3Njc2ODEyN15BMl5BanBnXkFtZTcwNTAwMzc3NA@@._V1_SX300.jpg
我尝试了很多,也使用 http_response_code(403) 并没有成功... 谢谢你的帮助...
我的代码如下:
<div class="poster">
<?php
$posterAll = $movie->posterUrl;
$file_headers=@get_headers($posterAll);
if(!$file_headers || $file_headers[0]=='HTTP/1.1 404 Not Found' || $file_headers[0]=='Not Found' || (strpos($headers[0], '403'))){
$exists=false;
}
else{
$exists=true;
}
echo $exists;
if ($exists) {
$imageData = base64_encode(file_get_contents($posterAll));
echo '<img height="300" width="300" src="data:image/jpeg;base64,' . $imageData . '">';
}
【问题讨论】:
标签: php