搜索
 找回密码
 加入

修改Discuz的附件防盗链系统

ctgwglzc 2007-2-6 10:46:15 1873
修改Discuz的附件防盗链系统

目的是为了增加几个允许调用附件的主机。

文件:attachment.php

将16-19行的
  1. </p>
  2. <p>if($attachrefcheck && $_SERVER['HTTP_REFERER'] && preg_replace("/https?:\/\/([^\/]+).*/i", "\\1", $_SERVER['HTTP_REFERER']) != $_SERVER['HTTP_HOST']) </p>
  3. <p>{</p>
  4. <p>/header("Location: {$boardurl}images/common/invalidreferer.gif");<br />showmessage('attachment_referer_invalid', NULL, 'HALTED');<br />}<br />
复制代码

修改为
  1. // 为Discuz增加几个允许调用附件的主机 开始

  2. $hostsAllowed = array(
  3. $_SERVER['HTTP_HOST'],

  4. "think-different.cn",
  5. "www.think-different.cn",
  6. "bbs.think-different.cn",

  7. "osx86china.com",
  8. "www.osx86china.com",
  9. "bbs.osx86china.com",

  10. "heartstringz.net",
  11. "www.heartstringz.net",

  12. "heartstrings.cn"
  13. );
  14. $j = 0;

  15. if($attachrefcheck && $_SERVER['HTTP_REFERER'])
  16. {
  17. for($i=0;$i<count($hostsAllowed);$i++)
  18. {
  19. if(preg_replace("/https?:\/\/([^\/]+).*/i", "\\1", $_SERVER['HTTP_REFERER']) != $hostsAllowed[$i])
  20. {
  21. $j++;
  22. }
  23. }

  24. if($j == count($hostsAllowed))
  25. {
  26. showmessage('attachment_referer_invalid', NULL, 'HALTED');
  27. }
  28. }

  29. //结束
复制代码

0 回复

高级模式
游客