php个人工作经验以及生活体会博客 php工作,生活

28十二/1143

制作外链工具原理

应单位需要做了一款外链工具,以加强网站的seo。
我在这里记录一下我做这款外链工具的程序原理。
基本原理:使用ajax结合php的技术远程抓取文件,从而达到运行该文件刷链的目的。
接下来记录一下具体是怎么做的:
结构:我们需要这样几个文件:jquery-1.5.1.js,index.php,urls.php,fun.php,backdata.php。
其中,jquery-1.5.1.js大家都知道(你懂的,下载一个就行了),这里就不用多说了
index.php是工具执行的索引程序
urls.php要刷链的网址都放在这里面
fun.ph扩展函数
backdata.php是ajax的请求数据地址
下面,贴出代码:
index.php:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
header("Content-type: text/html; charset=utf-8");
?>
<style type="text/css">
.box{ height:25px; width:550px; overflow:hidden;font-size:12px;}
.num{height:25px; width:50px; float:left; overflow:hidden; line-height:25px; text-align:center;}
.box_url{ height:25px; width:450px; float:left; overflow:hidden; line-height:25px; text-align:left;}
.box_text{ height:25px; width:50px; float:left; overflow:hidden; line-height:25px; text-align:right;}
</style>
<script type="text/javascript" src="jquery-1.5.1.js"></script>
<?php
require('fun.php');//调用扩展函数
require('urls.php');//调用需要刷链的网址
$num=count($urls); //刷链网址个数
$yuming=empty($_GET['yuming'])?'':$_GET['yuming'];//需要刷的域名
$page=empty($_GET['page'])?'':$_GET['page'];//页码
$cishu=10;//每页刷链条数
?>
<!--输出刷链的模板-->
<center>
<?php  for ($i=0;$i<$cishu;$i++){?>
<div class="box" id="link<?php echo $i;?>">请等待...</div>
<?php }?>
</center>
<!--输出刷链的模板end-->
<?php
if($page*$cishu>=$num+$cishu)$newurl=1;//判断是否将所有网址都刷过
else $newurl=0;
if(isset($yuming)&&!empty($yuming)){
    if(isset($page)){
        if(empty($page))$page='1';
        if($newurl==1)echo "<SCRIPT language=JavaScript>this.location.href='?yuming=".$yuming."&page=1';</SCRIPT>";//如果所有网址都循环刷了一遍就从头开始
        else{
            $string='';
?>
<!--执行Ajax请求数据-->
<script type="text/javascript">
$(document).ready(function(){
            <?php
            for ($i=0;$i<$cishu;$i++){
                $urlnum=($page-1)*$cishu+$i+1;
                $the_url=str_replace('{$url}',$yuming,$urls[$urlnum]);//替换域名,得到真实网址
?>

    $.post("backdata.php",{url:<?php echo '"'.$the_url.'"';?>,num:<?php echo $urlnum;?>},function(data){
        $("#link<?php echo $i;?>").html(data);
    });
<?php       }?>
});
</script>
<!--执行Ajax请求数据end-->
<?php
        }  
    }
    else exit('非法进入');
}
else exit('非法进入');
if($newurl==1){//如果所有网址都循环刷了一遍就把网址的顺序打乱一遍
    shuffle($urls);
    $urlsname='urls';
    file_put_contents($urlsname.'.php','<?php $'.$urlsname.'='.var_export($urls, true).';?>');
}
$page=$page+1;
?>
<!--10秒之后进入下一页-->
<script type="text/javascript">
$(document).ready(function(){
/*自定义倒计时10秒*/
var t = 10;//倒计时设置时间
$("#time").html(t);
function getTimes(){
    if(t>0){
        t = t - 1;
        $("#time").html(t);
    }
    if(t==0)this.location.href='?yuming=<?php echo $yuming;?>&page=<?php echo $page;?>';
}
setInterval(getTimes,1000);
});
</script>
<!--自定义倒计时10秒-->
<center>请不要关闭窗口,<span id='time' style="color:#F00;"></span> 秒后自动跳入下一页</center>
<!--10秒之后进入下一页end-->

urls.php里面的网址比较多,我贴出20个就是了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php $urls=array (
  0 => 'http://tool.liehuo.net/pr/index.php?url={$url}',
  1 => 'http://www.oumuo.cn/tool.asp?weburl={$url}',
  2 => 'http://dict.soso.com/q?sc=dict&w={$url}',
  3 => 'http://modo520.cn/dh/alexa/?domain={$url}&chkall=on&alexa=1&google=1&baidu=1&msn=1&yahoo=1&links=1&sina=1&do163=1&sohu=1&qq=1&zhongsou=1&uptimebot=1&whois=1&googlerank=1',
  4 => 'http://www.emroom.com/alexa.asp?domain={$url}&chkall=on&googlerank=1&google=1&baidu=1&msn=1&yahoo=1&yisou=1&alexa=1&sina=1&sohu=1&do163=1&qq=1&whois=1&uptimebot=1&isou=1&links=1',
  5 => 'http://www.8d.cn/s?wd={$url}&domain=8d.cn&pid=sc_nr_10032&s=R&tag=',
  6 => 'http://tool.lply.com/?url={$url}',
  7 => 'http://post.soso.com/sobar.q?op=searchpost&kw={$url}&pid=',
  8 => 'http://www.dss.cn/chajian/pr/default.asp?domain={$url}&chkall=on&googlerank=1&google=1&baidu=1&msn=1&yahoo=1&yisou=1&links=1&sina=1&sohu=1&do163=1&qq=1&zhongsou=1&uptimebot=1&whois=1&alexa=1&ip=1&keys=1',
  9 => 'http://look.515888.net/tools/baiducha/index.asp?wd={$url}&long=1',
  10 => 'http://www.0668.tv/pr/?domain={$url}&Submit=%B2%E9%D1%AF&chkall=on&googlerank=1&google=1&baidu=1&msn=1&yahoo=1&yisou=1&links=1&sina=1&sohu=1&do163=1&qq=1&zhongsou=1&uptimebot=1&whois=1&alexa=1&ip=1&keys=1',
  11 => 'http://alexa.3m2n.com/?url={$url}',
  12 => 'http://www.ok365.com/search.html?k=site%3A{$url}&area=564&s=&e=',
  13 => 'http://www.vkbbs.com/alexa.asp?url={$url}',
  14 => 'http://cnweb.search.live.com/images/results.aspx?q={$url}&FORM=BIRE',
  15 => 'http://www.robtex.com/dns/{$url}.html',
  16 => 'http://tool.163k.com/PR/?domain={$url}&chkall=on&googlerank=1&google=1&baidu=1&zhongsou=1&yahoo=1&links=1&do163=1&sohu=1&qq=1&alexa=1&whois=1',
  17 => 'http://www.pqshow.com/alexa/Index.asp?url={$url}',
  18 => 'http://www.ctbuxiu.com/alexa/Index.asp?url={$url}',
  19 => 'http://www.webchar.com/alexa/?domain={$url}&Submit=%B2%E9%D1%AF&chkall=on&googlerank=1&google=1&baidu=1&zhongsou=1&yahoo=1&links=1&do163=1&sohu=1&qq=1&alexa=1&whois=1',
  20 => 'http://www.all-list.cn/tools/indexed.do?domain={$url}'
?>

fun.php代码:

1
2
3
4
5
6
7
8
9
10
11
<?php
function curl_exe($url,$print='1'){
        $curl = curl_init(); //初始化一个 cURL 对象
        curl_setopt($curl, CURLOPT_URL, $url);//设置你需要抓取的URL    
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, $print);//设置cURL 参数,设置0,显示在网页中,设置1,不显示在网页中。     
        //综上我们就完成其基础的配置,现在执行抓取了。
        $data = curl_exec($curl); //运行cURL,请求网页
        curl_close($curl); //关闭URL请求
        return $data;
}
?>

backdata.php代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
require('fun.php');//调用扩展函数
$the_url=$_POST['url'];
$num=$_POST['num'];
$string='';
$string .= '<div class="num">['.$num.']</div><div class="box_url"><a href='."$the_url".' target="_blank">'.$the_url.'</a></div>';
$data=curl_exe($the_url);//抓取文件,运行网址
if(strlen($data)>100)$string .= '<div class="box_text">ok</div>';
else{
    $string .= '<div class="box_text">false</div>';
}
echo $string;
?>

演示地址:http://www.pk137.com:99/?yuming=58w.cn&page=1