当前位置:首页>网站教程>网站安全>网站无插件实现WordPress 外链安全跳转

网站无插件实现WordPress 外链安全跳转

无插件实现WordPress 外链安全跳转,类似知乎安全中心跳转

演示,本站就是用的这个

演示链接:http://www.baidu.com

跳转文件有两个版本,本站就是用的第二个版本,第二个版本在最后面

废话不多说,直接上代码:

首先在WordPress根目录新建文件 link.php ,内容如下:

link.php文件有两个版本,第二个版本在最后面

<?php
if(strlen($_SERVER['REQUEST_URI']) > 255 ||
strpos($_SERVER['REQUEST_URI'], "eval(") ||
strpos($_SERVER['REQUEST_URI'], "base64")) {
@header("HTTP/1.1 414 Request-URI Too Long");
@header("Status: 414 Request-URI Too Long");
@header("Connection: Close");
@exit;
}
//通过 QUERY_STRING 取得完整的传入数据,然后取得 url=之后的所有值,兼容性更好
$t_url = preg_replace('/^url=(.*)$/i','$1',$_SERVER["QUERY_STRING"]);
//数据处理
if(!empty($t_url)) {
//判断取值是否加密
if ($t_url == base64_encode(base64_decode($t_url))) {
$t_url = base64_decode($t_url);
}
//对取值进行网址校验和判断
preg_match('/^(http|https|thunder|qqdl|ed2k|Flashget|qbrowser):\/\//i',$t_url,$matches);
if($matches){
$url=$t_url;
$title='页面加载中,请稍候...';
} else {
preg_match('/\./i',$t_url,$matche);
if($matche){
$url='http://'.$t_url;
$title='页面加载中,请稍候...';
} else {
$url = 'http://'.$_SERVER['HTTP_HOST'];
$title='参数错误,正在返回首页...';
}
}
} else {
$title = '参数缺失,正在返回首页...';
$url = 'http://'.$_SERVER['HTTP_HOST'];
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
<meta name="robots" content="noindex, nofollow" />
<noscript><meta http-equiv="refresh" content="1;url='<?php echo $url;?>';"></noscript>
<script>
function link_jump()
{
//禁止其他网站使用我们的跳转页面
var MyHOST = new RegExp("<?php echo $_SERVER['HTTP_HOST']; ?>");
if (!MyHOST.test(document.referrer)) {
location.href="http://" + MyHOST;
}
}
//延时 2S 跳转,可自行修改延时时间
setTimeout(link_jump, 1000);
//延时 50S 关闭跳转页面,用于文件下载后不会关闭跳转页的问题
setTimeout(function(){window.opener=null;window.close();}, 50000);
</script>
<title><?php echo $title;?></title>
<style>body{margin:0;padding:0 30px;background:#fff;font-size:12px}img{border:none}a{text-decoration:none;cursor:pointer;outline:0}a:hover{text-decoration:underline}a,a:link,a:visited{color:#1e5494}a.btn_blue:focus{border-color:#93d4fc;box-shadow:0 0 5px #60caff}a.btn_blue{display:inline-block;padding:6px 25px;margin:0;font-size:14px;font-weight:700;text-align:center;border-radius:3px;border:1px solid #0d659b;color:#fff;color:#fff!important;background-color:#238aca;background:-moz-linear-gradient(top,#238aca,#0074bc);background:-webkit-linear-gradient(top,#238aca,#0074bc);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#238aca', endColorstr='#0074bc');-ms-filter:"progid:DXImageTransform.Microsoft.gradient(startColorstr='#238aca', endColorstr='#0074bc')"}a.btn_blue:hover{text-decoration:none;background-color:#238aca;background:-moz-linear-gradient(top,#2a96d8,#0169a9);background:-webkit-linear-gradient(top,#2a96d8,#0169a9);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#2a96d8', endColorstr='#0169a9');-ms-filter:"progid:DXImageTransform.Microsoft.gradient(startColorstr='#2a96d8', endColorstr='#0169a9')"}a.btn_blue:active{background-color:#238aca;background:-moz-linear-gradient(top,#0074bc,#238aca);background:-webkit-linear-gradient(top,#0074bc,#238aca);filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#0074bc', endColorstr='#238aca');-ms-filter:"progid:DXImageTransform.Microsoft.gradient(startColorstr='#0074bc', endColorstr='#238aca')";outline:0}.remind_block{overflow:hidden}.remind_block .remind_content{overflow:hidden}.remind_block .remind_title{margin-bottom:10px;padding-top:3px;font-weight:700;font-size:20px;font-family:"Microsoft YaHei","lucida Grande",Verdana}.remind_block .remind_detail{line-height:1.5;font-size:16px;color:#535353}.warning .remind_title{color:#16a085}.container{max-width:640px;margin:0 auto;padding-top:25px}.header{margin-bottom:5px}.footer{margin-top:18px;text-align:center;color:#a0a0a0;font-size:10px}.content{border:1px solid #bbb;box-shadow:0 0 3px #d4d4d4}.c-container{padding:30px}.c-footer{padding:10px 15px;background:#f1f1f1;border-top:1px solid #bbb;overflow:hidden}.c-footer-a1,.c-footer-a2{float:left}.c-footer-a2{margin:8px 0 0 15px}.safety-url{margin-bottom:15px;padding-bottom:15px;border-bottom:1px solid #dfdfdf;word-wrap:break-word;word-break:break-all}</style>
</head>
<body>
<div class="container">
<div class="content">
<div class="c-container warning">
<div id="remind_block" class="remind_block" style="height: 260px;">
<div class="remind_content">
<div class="remind_title">
您将要访问:
</div>
<div class="remind_detail">
<div class="safety-url">
<?php echo $url;?>
</div>
<span style="color:#CC0000;font-weight:800;">访问提示:</span>
<br/>您即将离开本站<br/>该网页可能包含未知的安全隐患,请注意您的账号和财产安全。
</div>
</div>
</div>
</div>
</div>
<div class="c-footer">
<a href="<?php echo $url;?>" rel="nofollow" class="c-footer-a1 btn_blue">继续访问</a><a class="c-footer-a2" href="/" rel="nofollow">返回主页</a>
</div>
</div>
<div class="footer">Copyright © WordPress </div>
</body>
</html>
 

第二步,修改主题文件下内 functions.php 在合适位置(一般在最底部,如主题升级修改了此文件,需要在升级主题后重新插入)插入如下代码:

add_filter('the_content','the_content_nofollow',999);
function the_content_nofollow($content) {
  preg_match_all('/<a(.*?)href="(.*?)"(.*?)>/',$content,$matches);
  if($matches){
    foreach($matches[2] as $val){
      if(strpos($val,'://')!==false && strpos($val,home_url())===false && !preg_match('/\.(jpg|jepg|png|ico|bmp|gif|tiff)/i',$val)){
        $content=str_replace("href=\"$val\"", "href=\"".home_url()."/link.php?url=$val\"  target=_blank ",$content);
      }
    }
  }
  return $content;
}

link.php版本二:

 <?php
    //$t_url=$_GET['url']; //此代码无法支持带请求参数的目的地址,已弃用!
    $t_url = preg_replace('/^url=(.*)$/i','$1',$_SERVER["QUERY_STRING"]); //这个支持
    if(!empty($t_url)) {
        preg_match('/(http|https):\/\//',$t_url,$matches);
    if($matches){
        $url=$t_url;
        $title='页面加载中,请稍候...';
    } else {
        preg_match('/\./i',$t_url,$matche);
        if($matche){
            $url='http://'.$t_url;
            $title='页面加载中,请稍候...';
        } else {
            $url='http://www.laipang.com/';
            $title='参数错误,正在返回首页...';
        }
    }
    } else {
        $title='参数缺失,正在返回首页...';
        $url='http://www.laipang.com/';
    }
    ?>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="refresh" content="1;url='<?php echo $url;?>';">
    <title><?php echo $title;?></title>
<style>
/* Main styles */
@import url(https://fonts.googleapis.com/css?family=Open+Sans:800);
.text {
  fill: none;
  stroke-width: 2;
  stroke-linejoin: round;
  stroke-dasharray: 70 330;
  stroke-dashoffset: 0;
  -webkit-animation: stroke 6s infinite linear;
  animation: stroke 3s infinite linear;
}
.text:nth-child(5n + 1) {
  stroke: #F2385A;
  -webkit-animation-delay: -1.2s;
  animation-delay: -1.2s;
}
.text:nth-child(5n + 2) {
  stroke: #F5A503;
  -webkit-animation-delay: -2.4s;
  animation-delay: -2.4s;
}
.text:nth-child(5n + 3) {
  stroke: #E9F1DF;
  -webkit-animation-delay: -3.6s;
  animation-delay: -3.6s;
}
.text:nth-child(5n + 4) {
  stroke: #56D9CD;
  -webkit-animation-delay: -4.8s;
  animation-delay: -4.8s;
}
.text:nth-child(5n + 5) {
  stroke: #3AA1BF;
  -webkit-animation-delay: -6s;
  animation-delay: -6s;
}

@-webkit-keyframes stroke {
  100% {
    stroke-dashoffset: -400;
  }
}
@keyframes stroke {
  100% {
    stroke-dashoffset: -400;
  }
}
/* Other styles */
html, body {
  height: 100%;
}

body {
  background: #111;
  background-size: .2em 50%;
  font: 3em/1 Open Sans, Impact;
  text-transform: uppercase;
  margin: 0;
}

svg {
  position: absolute;
  width: 100%;
  height: 100%;
}
</style>
</head>
<body>

<svg viewBox="0 0 600 300">
  <!-- Symbol-->
  <symbol id="s-text">
    <text text-anchor="middle" x="50%" y="50%" dy=".33em">加载中,请稍后...</text>
  </symbol>
  <!-- Duplicate symbols-->
  <use class="text" xlink:href="#s-text"></use>
  <use class="text" xlink:href="#s-text"></use>
  <use class="text" xlink:href="#s-text"></use>
  <use class="text" xlink:href="#s-text"></use>
  <use class="text" xlink:href="#s-text"></use>
</svg>
    </html>

赖胖提醒:如果想省事就下载上传

下载权限
查看
  • 免费下载
    评论并刷新后下载
    登录后下载
  • {{attr.name}}:
您当前的等级为
登录后免费下载登录 小黑屋反思中,不准下载! 评论后刷新页面下载评论 支付以后下载 请先登录 您今天的下载次数(次)用完了,请明天再来 支付积分以后下载立即支付 支付以后下载立即支付 您当前的用户组不允许下载升级会员
您已获得下载权限 您可以每天下载资源次,今日剩余
免责声明 1:本站的课程与素材,都是电子版课件,非实物光盘,课件由百度网盘发送.(百度网盘下载教程)2:本站所有涉及视频及素材,软件等由互联网搜索收集而来,本站不拥有此类资料的版权。3:本站所有视频,素材及软件不加密、不限时、可永久观看或使用!禁止二次销售,否则因此引起的一切问题与本站无关。4:本站所有的资源均为免费提供,提供资料的目的是让大家学习和交流,所收取的相关费用非资料销售费用,而是资料收集整理手工费。5:无意侵害您的权益,请发送邮件至 590173@qq.com 或点击左侧 私信:站长反馈,我们将尽快处理。

给TA打赏
共{{data.count}}人
人已打赏
WordPress插件

W3 Total Cache Pro v2.4.0 汉化版 – WordPress缓存插件

2023-8-6 13:12:09

网站安全

什么是域名的DNSSEC安全扩展?

2023-7-10 15:10:05

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索