php教程

php破解图床防盗链方法

我的站长站 2021-10-27 人阅读

php代码

命名为dl.php

<?php
class ImgBridge{
private $water='';
private $imgUrl='';
private $referer='';
private $ua='MQQBrowser/26 Mozilla/5.0 (Linux; U; Android 2.3.7; zh-cn; MB200 Build/GRJ22; CyanogenMod-7) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1';
private $imgCode='';
private $imgHeader='';
private $imgBody='';
private $imgType='';
public function __construct($config=array()){
foreach($config as $key=>$value){
$this->$key=$value;
}
}
public function getImg($imgUrl){
$this->imgUrl=$imgUrl;
/** 处理url */
if(substr($this->imgUrl,0,7)!=='http://' && substr($this->imgUrl,0,8)!=='https://'){
$this->imgUrl='http://'.$this->imgUrl;
}
/** 解析url中的host */
$url_array=parse_url($this->imgUrl);
/** 设置referer */
$this->referer=$this->referer==""?'http://'.$url_array['host']:$this->referer;
/**开始获取 */
$this->urlOpen();
$this->imgBody;
/**处理错误 */
if($this->imgCode!=200){
$this->error(1);
exit();
}
/**获取图片格式 */
preg_match("/Content-Type: image/(.+?)n/sim",$this->imgHeader,$result);
/**看看是不是图片 */
if(!isset($result[1])){
$this->error(2);
exit();
}else{
$this->imgType=$result[1];
}
/** 输出内容 */
$this->out();       
}
private function out(){
/** gif 不处理,直接出图 */
if($this->imgType=='gif'){
header("Content-Type: image/gif");
echo $this->imgBody;
exit();
}
header("Content-Type: image/png");
/** 其他类型的,加水印 */
$im=imagecreatefromstring($this->imgBody);
$white = imagecolorallocate($im, 255, 255, 255);
/*加上水印*/
if($this->water){
imagettftext($im, 12, 0, 20, 20, $white, "/fonts/hwxh.ttf", $this->water);           
}
imagepng($im);
}
private function error($err){
header("Content-Type: image/jpeg");
$im=imagecreatefromstring(file_get_contents('./default.jpg'));
imagejpeg($im);
}
private function urlOpen()
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->imgUrl);
curl_setopt($ch, CURLOPT_USERAGENT, $this->ua);
curl_setopt ($ch,CURLOPT_REFERER,$this->referer);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
/**跳转也要 */
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
/**  支持https */
$opt[CURLOPT_SSL_VERIFYHOST] = 2;
$opt[CURLOPT_SSL_VERIFYPEER] = FALSE;
curl_setopt_array($ch, $opt);
$response = curl_exec($ch);
$this->imgCode=curl_getinfo($ch, CURLINFO_HTTP_CODE) ;
if ($this->imgCode == '200') {
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$this->imgHeader = substr($response, 0, $headerSize);
$this->imgBody = substr($response, $headerSize);
return ;
}
curl_close($ch);
}
}
$img=new ImgBridge(array('water'=>''));
$img->getImg(strstr($_SERVER["QUERY_STRING"], "http"));

使用方法

http://域名/dl.php?url=图床链接

示例

https://image.135editor.com/files/users/740/7407329/201912/zTeFAx8R_Cmea.jpg

加上反向dai理,破解防盗链处理

http://域名/dl.php?url=https://image.135editor.com/files/users/740/7407329/201912/zTeFAx8R_Cmea.jpg

HTML格式

<img src="http://域名/dl.php?url=https://image.135editor.com/files/users/740/7407329/201912/zTeFAx8R_Cmea.jpg"/>
相关推荐
  • php代码
  • 防盗链
  • 支付宝企业账户转账个人账户php接口代码

    前言支付宝企业账户转账个人账户php接口代码,该接口主要用于平台对用户奖励的发放,场景也很简单就是我在你平台上有余额,我提现,平台给钱。只不过项目中是用的官方的SDK调用的,仔细看了下那个SDK目录,把很多无用的接口(目前自己用不上)也包含在里面,作为强...

    php教程 160 2年前
  • php判断目录文件是否存在

    一段简单的php判断目录文件是否存在代码,收藏记录一下,以后肯定用得到的。<?php$filename = &#39;../../e/install/&#39;; if (file_exists($filename)) { echo "<h3><div align=&#39;center&#39;><font color=&#39;#FF0000&#39;>存在安全风险!请将 ...

    php教程 115 2年前
  • curl函数获取API接口数据方法

    PHP利用curl函数,获取API接口数据方法示例代码,自用收藏<?php $weather = curl_init(); curl_setopt($weather,CURLOPT_URL,"https://api.pc2801.com/cqssc/".time()); curl_setopt($weather, CURLOPT_SSL_VERIFYPEER, false); //如果...

    php教程 89 2年前
  • nginx文件防盗链配置方法

    Nginx的核心模块中已经有了防盗链的相关功能。在配置Nginx之前,我们需要先确认Nginx是否开启了防盗链模块。如果没有开启,则需要重新编译Nginx或者安装对应的模块。防盗链配置方法Nginx的防盗链功能可以通过配置文件中的location指令来实现。我们需要...

    服务器配置 21 6个月前
  • 一句话破解微信图片防盗链方法

    经常扒站的朋友应该了解,如果扒站是微信的,图片N多,微信图片又是不能引用的,只能下载下来,感觉实在是太麻烦了。因为这些图片有防盗链,如果网页直接引用的话会出现不可用,直接打开的话可以就直接用,所以就有了解决方法:<?phpheader("content-type:image/jpeg"...

    php教程 130 3年前
  • 利用web.config伪静态规则实现防盗链功能

    防盗链的几种简单方法第一种:加水印,盗链无非也就是盗取网站上的资源,一般资源图片居多,在就是视频了。通通加上网站水印,还可以让盗链者帮忙宣传下网站。第二种:装防盗链软件,一般的服务器软件都带这种功能,推荐使用宝塔,安全狗。第三钟:加伪静态规则,判断来路...

    经验分享 810 5年前
最新更新