修改Discuz的附件防盗链系统
目的是为了增加几个允许调用附件的主机。
文件:attachment.php
将16-19行的
- </p>
- <p>if($attachrefcheck && $_SERVER['HTTP_REFERER'] && preg_replace("/https?:\/\/([^\/]+).*/i", "\\1", $_SERVER['HTTP_REFERER']) != $_SERVER['HTTP_HOST']) </p>
- <p>{</p>
- <p>/header("Location: {$boardurl}images/common/invalidreferer.gif");<br />showmessage('attachment_referer_invalid', NULL, 'HALTED');<br />}<br />
复制代码
修改为
- // 为Discuz增加几个允许调用附件的主机 开始
- $hostsAllowed = array(
- $_SERVER['HTTP_HOST'],
- "think-different.cn",
- "www.think-different.cn",
- "bbs.think-different.cn",
- "osx86china.com",
- "www.osx86china.com",
- "bbs.osx86china.com",
- "heartstringz.net",
- "www.heartstringz.net",
- "heartstrings.cn"
- );
- $j = 0;
- if($attachrefcheck && $_SERVER['HTTP_REFERER'])
- {
- for($i=0;$i<count($hostsAllowed);$i++)
- {
- if(preg_replace("/https?:\/\/([^\/]+).*/i", "\\1", $_SERVER['HTTP_REFERER']) != $hostsAllowed[$i])
- {
- $j++;
- }
- }
- if($j == count($hostsAllowed))
- {
- showmessage('attachment_referer_invalid', NULL, 'HALTED');
- }
- }
- //结束
复制代码 |