Discuz教程网

Discuz X2 RC实现URL跳转,屏蔽外部链接

[复制链接]
authicon dly 发表于 2012-2-29 16:09:13 | 显示全部楼层 |阅读模式
Discuz X2自动实现外部链接跳转,防止灌水。
找到source\function\function_discuzcode.php文件
修改函数function parseurl($url, $text, $scheme){....}为
  1. function parseurl($url, $text, $scheme) {
  2. global $_G;
  3. if(!$url && preg_match("/((https?|ftp|gopher|news|telnet|rtsp|mms|callto|bctp|thunder|qqdl|synacast){1}:\/\/|www\.)[^\["']+/i", trim($text), $matches)) {
  4.   $url = $matches[0];
  5.   $length = 65;
  6.   if(strlen($url) > $length) {
  7.    $text = substr($url, 0, intval($length * 0.5)).' ... '.substr($url, - intval($length * 0.3));
  8.   }
  9.   $url = substr(strtolower($url), 0, 4) == 'www.' ? 'http://'.$url : $url;
  10. } else {
  11.   $url = substr($url, 1);
  12.   if(substr(strtolower($url), 0, 4) == 'www.') {
  13.    $url = 'http://'.$url;
  14.   }
  15.   $url = !$scheme ? $_G['siteurl'].$url : $url;
  16. }
  17. preg_match("/^http:\/\/[^\/]+/",$url,$matchs);
  18. $allowURL = array(".com");//这个是允许的域名
  19. if(!in_array(substr($matchs[0],7),$allowURL)){
  20.   $url = "http://haodehui.com/goto.php?url=".base64_encode($url);//这个是跳转后的网址,
  21. //url使用的base64_encode加密方式,用base64_decode解密就行
  22. }
  23. return '<a href="'.$url.'" target="_blank">'.$text.'</a>';
  24. }

复制代码



上一篇:今天早上出现了部分页面点击进去后出现空白
下一篇:Dixcuz X2怎么设置邮件发送时显示发件人名称
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-3 03:41

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表