当前位置: 首页 > 图文教程 > 网络编程 > PHP > php实现首页链接查询 友情链接检查的代码

PHP
php 服务器调试 Zend Debugger 的安装教程
从Web查询数据库之PHP与MySQL篇
php 应用程序安全防范技术研究
php 不同编码下的字符串长度区分
php 生成饼图 三维饼图
PHP 字符截取 解决中文的截取问题,不用mb系列
PHP5 操作MySQL数据库基础代码
php面向对象全攻略 (一) 面向对象基础知识
php面向对象全攻略 (二) 实例化对象 使用对象成员
php面向对象全攻略 (三)特殊的引用“$this”的使用
php面向对象全攻略 (四)构造方法与析构方法
php面向对象全攻略 (五) 封装性
php面向对象全攻略 (六)__set() __get() __isset() __unset()的用法
php面向对象全攻略 (七) 继承性
php面向对象全攻略 (八)重载新的方法
php面向对象全攻略 (九)访问类型
php面向对象全攻略 (十) final static const关键字的使用
php面向对象全攻略 (十一)__toString()用法 克隆对象 __call处理调用错误
php面向对象全攻略 (十二) 抽象方法和抽象类
php面向对象全攻略 (十四) php5接口技术

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 194 ::
收藏到网摘: n/a

网站首页超链接反查 友情链接查询 外链查询 ,对于其中的思路
复制代码 代码如下:

<?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>输入域名 如:ruanchen.com
</form>';
}
?>