Home >Backend Development >PHP Tutorial >How to bypass image hotlink protection in PHP

How to bypass image hotlink protection in PHP

WBOY
WBOYOriginal
2016-07-25 08:59:511627browse
  1. <script>window.sc="<img src='http://cdn.jbxue.com//uploads/2011/06/1309476244-elicium-rai-01-528x351.jpg?" +Math.random()+"'>";</script>
Copy code

2. Curl method usage:

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

3. PHP header sends various types of files for download File name: 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. With the above code, you can display the image like this:

Copy code

It’s really a step up from the top, and the PHP image hotlink protection can’t hold the line of defense like this, haha.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn