当前位置:Gxlcms > PHP教程 > php中图片防盗链如何绕过的方法

php中图片防盗链如何绕过的方法

时间:2021-07-01 10:21:17 帮助过:19人阅读

2、curl的方法 用法:

  1. http://your-domain-name/showpic.php?url=image_url

3、PHP header发送各种类型文件下载 文件名:showpic.php

  1. $url = $_GET["url"];
  2. //$url = str_replace("http:/","http://",$url);
  3. $dir = pathinfo($url);
  4. $host = $dir['dirname'];
  5. $refer = $host.'/';
  6. $ch = curl_init($url);
  7. curl_setopt ($ch, CURLOPT_REFERER, $refer);
  8. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);//激活可修改页面,Activation can modify the page
  9. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  10. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  11. $data = curl_exec($ch);
  12. curl_close($ch);
  13. $ext = strtolower(substr(strrchr($img,'.'),1,10));
  14. $types = array(
  15. 'gif'=>'image/gif',
  16. 'jpeg'=>'image/jpeg',
  17. 'jpg'=>'image/jpeg',
  18. 'jpe'=>'image/jpeg',
  19. 'png'=>'image/png',
  20. );
  21. $type = $types[$ext] ? $types[$ext] : 'image/jpeg';
  22. header("Content-type: ".$type);
  23. echo $data;
  24. ?>

遇到PHP 提示错误Cannot modify header information headers already sent ,原因在于:这些代码之前不要有任何内容输出的,包括空白,切记!

有了以上的代码,就可以这样显示图片了:

真是道高一尺,魔高一丈啊,php图片防盗链就这样没有守住防线,哈哈。

人气教程排行