这里提供一种临时处理的思路:既然新浪判断了Referer,我们伪造就是了
最后用API方式调用,例如:api.php?url=新浪外链地址
远程图片
<?php/** * @description: curl_get 获取远程图片 * @param 图片url * @return: 获取到的图片文件流 */ function curl_get($url){ $ch = curl_init($url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Linux; U; Android 4.4.1; zh-cn; R815T Build/JOP40D) AppleWebKit/533.1 (KHTML, like Gecko)Version/4.0 MQQBrowser/4.5 Mobile Safari/533.1'); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $content = curl_exec($ch); curl_close($ch); return ($content);}/** * @description: 对传入的URL做安全化处理 * @param 图片URL * @return: 如果不安全 则退出;反之返回原url */ function waf($url){ if (is_array($url)) { return false; } $blacklist = array('file', 'dict', 'gopher', 'php', '///', './'); foreach ($blacklist as $key) { if (stripos($url, $key) !== false) return false; } if (stripos(parse_url($url, PHP_URL_HOST), "sinaimg.cn") == false) { return false; } return $url;} @$url = $_GET['url']; /**判断REFERER 防止他人盗取. */ if (isset($_SERVER['HTTP_REFERER'])) { if (stripos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST']) === false) { die("Error"); }}if ($url = waf($url)) { header("Content-Type: image/jpeg;text/html; charset=utf-8"); echo curl_get($url);} else { die("ERroR");}
转载于蓝优博客 https://umqun.com/Code/16.html