苹果cms最全解决新浪图床防盗链教程

2020-03-1523:25:48 发表评论 1,192

 

2019年4月是一个特殊的日子,这是个 博客主或部分站长的噩耗,那就是新浪图床开启了图片防盗链,解决新浪图床防盗链的方法有很多,今天我们就来说一说其中的一种,下面看教程:

1.新建一个PHP文件,我们把它命名为:“sina.php”写入如下代码:

<span class="token delimiter">&lt;?php</span> <span class="token variable">$url</span> <span class="token operator">=</span> <span class="token variable">$_GET</span><span class="token punctuation">[</span><span class="token string">"url"</span><span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token variable">$dir</span> <span class="token operator">=</span> <span class="token function">pathinfo</span><span class="token punctuation">(</span><span class="token variable">$url</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token variable">$host</span> <span class="token operator">=</span> <span class="token variable">$dir</span><span class="token punctuation">[</span><span class="token string">'dirname'</span><span class="token punctuation">]</span><span class="token punctuation">;</span> <span class="token variable">$refer</span> <span class="token operator">=</span> <span class="token variable">$host</span><span class="token punctuation">.</span><span class="token string">'/'</span><span class="token punctuation">;</span> <span class="token variable">$ch</span> <span class="token operator">=</span> <span class="token function">curl_init</span><span class="token punctuation">(</span><span class="token variable">$url</span><span class="token punctuation">)</span><span class="token punctuation">;</span> curl_setopt <span class="token punctuation">(</span><span class="token variable">$ch</span><span class="token punctuation">,</span> <span class="token constant">CURLOPT_REFERER</span><span class="token punctuation">,</span> <span class="token variable">$refer</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token function">curl_setopt</span><span class="token punctuation">(</span><span class="token variable">$ch</span><span class="token punctuation">,</span> <span class="token constant">CURLOPT_RETURNTRANSFER</span><span class="token punctuation">,</span> <span class="token boolean">true</span><span class="token punctuation">)</span><span class="token punctuation">;</span><span class="token comment" spellcheck="true">//激活可修改页面,Activation can modify the page</span> <span class="token function">curl_setopt</span><span class="token punctuation">(</span><span class="token variable">$ch</span><span class="token punctuation">,</span> <span class="token constant">CURLOPT_RETURNTRANSFER</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token function">curl_setopt</span><span class="token punctuation">(</span><span class="token variable">$ch</span><span class="token punctuation">,</span> <span class="token constant">CURLOPT_BINARYTRANSFER</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token variable">$data</span> <span class="token operator">=</span> <span class="token function">curl_exec</span><span class="token punctuation">(</span><span class="token variable">$ch</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token function">curl_close</span><span class="token punctuation">(</span><span class="token variable">$ch</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token variable">$ext</span> <span class="token operator">=</span> <span class="token function">strtolower</span><span class="token punctuation">(</span><span class="token function">substr</span><span class="token punctuation">(</span><span class="token function">strrchr</span><span class="token punctuation">(</span><span class="token variable">$img</span><span class="token punctuation">,</span><span class="token string">'.'</span><span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token number">10</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token variable">$types</span> <span class="token operator">=</span> <span class="token keyword">array</span><span class="token punctuation">(</span> <span class="token string">'gif'</span><span class="token operator">=</span><span class="token operator">&gt;</span><span class="token string">'image/gif'</span><span class="token punctuation">,</span> <span class="token string">'jpeg'</span><span class="token operator">=</span><span class="token operator">&gt;</span><span class="token string">'image/jpeg'</span><span class="token punctuation">,</span> <span class="token string">'jpg'</span><span class="token operator">=</span><span class="token operator">&gt;</span><span class="token string">'image/jpeg'</span><span class="token punctuation">,</span> <span class="token string">'jpe'</span><span class="token operator">=</span><span class="token operator">&gt;</span><span class="token string">'image/jpeg'</span><span class="token punctuation">,</span> <span class="token string">'png'</span><span class="token operator">=</span><span class="token operator">&gt;</span><span class="token string">'image/png'</span><span class="token punctuation">,</span> <span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token variable">$type</span> <span class="token operator">=</span> <span class="token variable">$types</span><span class="token punctuation">[</span><span class="token variable">$ext</span><span class="token punctuation">]</span> <span class="token operator">?</span> <span class="token variable">$types</span><span class="token punctuation">[</span><span class="token variable">$ext</span><span class="token punctuation">]</span> <span class="token punctuation">:</span> <span class="token string">'image/jpeg'</span><span class="token punctuation">;</span> <span class="token function">header</span><span class="token punctuation">(</span><span class="token string">"Content-type: "</span><span class="token punctuation">.</span><span class="token variable">$type</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token keyword">echo</span> <span class="token variable">$data</span><span class="token punctuation">;</span>

2.在数据库中批量修改图片链接:

苹果cms v10视频图片替换命令如下:(部分站长的新浪地址是mac://开头,请自己检查)

UPDATE {pre}vod SET vod_pic=REPLACE(vod_pic, 'mac://ws3.sinaimg.cn', 'https://你的网址/sina.php?url=https://ws3.sinaimg.cn')

苹果cms专题图片替换代码:

UPDATE {pre}topic SET topic_pic=REPLACE(topic_pic, 'mac://ws3.sinaimg.cn', 'https://你的网址/sina.php?url=https://ws3.sinaimg.cn')

苹果cms文章图片替换代码:

UPDATE {pre}art SET art_pic=REPLACE(art_pic, 'mac://ws3.sinaimg.cn', 'https://你的网址/sina.php?url=https://ws3.sinaimg.cn')

 

头像

发表评论

您必须登录才能发表评论!