php实现首页链接查询 友情链接检查的代码

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

<?php
/*
* 网站首页超链接反查 友情链接查询 外链查询
* web技术爱好者 lost63.com原创 QQ:35501547
* 转载请注明出处
*/

if($_GET['action']=="check"){

$domain=$_POST['domain'];

//域名表单项为空,则获取地址栏参数
if($domain==""){
$domain=$_GET['domain'];
}

//网址
$url="http://".$domain;

//读取网页,返回网页源文件内容
function read_url($str){

$file=fopen($str,"r") or die($str.'->远程网址读取失败! <a href="?next='.($_GET['next']+1).'&action=check&domain='.$_GET['domain'].'">点击继续查询</a><br>');
while(!feof($file)){
$result.=fgets($file,9999);
}
fclose($file);
return $result;

}

//打开session
session_start();

//如果$_SESSION['matches']没有赋值就设置它;
if(!isset($_SESSION['matches'])){
$result=read_url($url);

preg_match_all('/<a(.*?)href="(http:\/\/.*?)"(.*?)>(.*?)<\/a>/i',$result,$matches);
$num=count($matches[2]);
for($i=0;$i<$num;$i++){
if(strpos($matches[2][$i],$domain)>0){
unset($matches[2][$i]);
}
}

$_SESSION['matches']=$matches[2];
}
//直接从session中取出包含网址数组;
$matches[2]=$_SESSION['matches'];

$n=count($matches[2]);

$next=0;
$next+=$_GET['next'];

$result=read_url($matches[2][$next]);

if(strpos($result,$domain)>0){
$value=$matches[2][$next].' <font color=green>true</font><br>';
}else{
$value=$matches[2][$next].' <font color=red>false</font><br>';
}
$values=$_COOKIE['check_result'].$value;
setcookie("check_result",$values,time()+3600);
echo $values;

if($next==$n){
echo "扫描结束!";
}else{
echo '<meta http-equiv="refresh" content="1;URL=?next='.($next+1).'&action=check&domain='.$domain.'" />';
}


}else{
//删除cookies
setcookie("check_result","",time()-3600);
echo '<form name="form1" method="post" action="?action=check">
<input type="text" name="domain">
<input type="submit" name="Submit" value="提交">
<font color="red">*</font>输入域名 如:jb51.net
</form>';
}
?>

相关文章

PHP中spl_autoload_register()和__autoload()区别分析

PHP中spl_autoload_register()和__autoload()区别分析

关于spl_autoload_register()和__autoload(),相信大多数都会选择前者了? 看两者的用法: 复制代码 代码如下://__autoload用法function...

php 数组的指针操作实现代码

/** * 将数组的内部指针倒回一位 * @param array &$arr * @return mixed 返回前一个单元的值,当没有更多单元时返回 FALSE * 如果数组包含空的...

PHP defined()函数的使用图文详解

PHP defined()函数的使用图文详解

PHP defined() 函数 例子 定义和用法 defined() 函数检查某常量是否存在。 若常量存在,则返回 true,否则返回 false。 语法 defined(name)...

php flush无效,IIS7下php实时输出的方法

在一个比较费时的操作中,想把操作记录在浏览器上实时显示出来,用到了flush(),把缓冲中的内容发送到浏览器。但在iis7里面用fastcgi模式配置的php怎么都实现不了,结果总是一起...

PHP 数组学习排序全接触第1/2页

array_values($arr) array 返回数组所有元素 复制代码 代码如下: <?php $arr = array("a", "b", "c"); $arr = arr...