php 网站同IP查询代码
<?php
if(function_exists('date_default_timezone_set')){
date_default_timezone_set('Asia/Shanghai'); //设定时区
}
define("APP_ROOT",dirname(dirname(__FILE__))); //网站根目录
function visitorIP(){ //访问者IP
if($_SERVER['HTTP_X_FORWARDED_FOR']){
$ipa = $_SERVER['HTTP_X_FORWARDED_FOR'];
}elseif($_SERVER['HTTP_CLIENT_IP']){
$ipa = $_SERVER['HTTP_CLIENT_IP'];
}else{
$ipa = $_SERVER['REMOTE_ADDR'];
}
return $ipa;
}
function cleanDomain($q,$w=0){ //整理域名 $w=1过滤www.前缀 $w=0不过滤
$q = htmlspecialchars(strtolower(trim($q)));
if(substr($q,0,7) == "http://" || substr($q,0,8) == "https://" || substr($q,0,6) == "ftp://"){
$q = str_replace("http:/","",$q);
$q = str_replace("https:/","",$q);
$q = str_replace("ftp:/","",$q);
}
if(substr($q,0,4) == "www." && $w==1) {
$q = str_replace("www.","",$q);
}
$q = trim($q,"/");
return $q;
}
//获取网页
class HTTPRequest
{
/*
获取网页
*/
var $_fp; // HTTP socket
var $_url; // full URL
var $_host; // HTTP host
var $_protocol; // protocol (HTTP/HTTPS)
var $_uri; // request URI
var $_port; // port
// scan url
function _scan_url()
{
$req = $this->_url;
$pos = strpos($req, '://');
$this->_protocol = strtolower(substr($req, 0, $pos));
$req = substr($req, $pos+3);
$pos = strpos($req, '/');
if($pos === false)
$pos = strlen($req);
$host = substr($req, 0, $pos);
if(strpos($host, ':') !== false)
{
list($this->_host, $this->_port) = explode(':', $host);
}
else
{
$this->_host = $host;
$this->_port = ($this->_protocol == 'https') ? 443 : 80;
}
$this->_uri = substr($req, $pos);
if($this->_uri == '')
$this->_uri = '/';
}
// constructor
function HTTPRequest($url)
{
$this->_url = $url;
$this->_scan_url();
}
// download URL to string
function DownloadToString()
{
$crlf = "rn";
$response="";
// generate request
$req = 'GET ' . $this->_uri . ' HTTP/1.0' . $crlf
. 'Host: ' . $this->_host . $crlf
. $crlf;
// fetch
$this->_fp = @fsockopen(($this->_protocol == 'https' ? 'ssl://' : '') . $this->_host, $this->_port);
@fwrite($this->_fp, $req);
while(is_resource($this->_fp) && $this->_fp && !feof($this->_fp))
$response .= fread($this->_fp, 1024);
@fclose($this->_fp);
// split header and body
$pos = strpos($response, $crlf . $crlf);
if($pos === false)
return($response);
$header = substr($response, 0, $pos);
$body = substr($response, $pos + 2 * strlen($crlf));
// parse headers
$headers = array();
$lines = explode($crlf, $header);
foreach($lines as $line)
if(($pos = strpos($line, ':')) !== false)
$headers[strtolower(trim(substr($line, 0, $pos)))] = trim(substr($line, $pos+1));
// redirection?
if(isset($headers['location']))
{
$http = new HTTPRequest($headers['location']);
return($http->DownloadToString($http));
}
else
{
return($body);
}
}
}
function get_html($siteurl) {
//将网页代码存入字符串
$r=new HTTPRequest($siteurl);
$htm=$r->DownloadToString();
return $htm;
}
$visitorip = visitorIP();
$q = cleanDomain($_POST['q']);
$q_encode = urlencode($q);
$title = "同IP站点查询";
$chaxun_status = 0; //查询状态 -1是没有查询参数,0是查询出错,1是查域名,2是查IP
if(isset($_GET['action']) && trim($_GET['action']) == "do"){ //AJAX调出数据
$ipArr = ReverseIP($q);
if(count($ipArr)>0){
echo '<p class="f14">在此IP找到了'.count($ipArr).'个域名,见下:</p>';
echo '<ul class="lst">';
for($i=0;$i<count($ipArr);$i++){
echo '<li><a href="http://'.$ipArr[$i].'/" title="访问 '.$ipArr[$i].'" target="_blank" class="f14 l200">'.$ipArr[$i].'</a></li>';
}
echo '</ul><div class="cboth"></div>';
}else{
echo '<p class="f14">没有找到IP '.$ip.' 对应的域名记录!</p>';
}
die();
}
function IpToInt($Ip){ //IP转为数字
$array=explode('.',$Ip);
$Int=($array[0] * 256*256*256) + ($array[1]*256*256) + ($array[2]*256) + $array[3];
return $Int;
}
function ReverseIP($q){
$htm = get_html('http://www.ip-adress.com/reverse_ip/'.$q);
preg_match_all('/<a href="/whois/(.*)">Whois</a>/', $htm, $tt);
$res = $tt[1];
return $res;
}
if(preg_match("/[a-zA-Z-_]+/si",$q)){ //如果查询的是域名
$ip = gethostbyname($q);
if($ip == $q){
$ip = $visitorip;
$chaxun_status = -1;
}else{
$chaxun_status = 1;
}
}elseif(ereg("^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$",$q)){ //如果查询的是IP
$ip = $q;
$chaxun_status = 2;
}else{
$ip = $visitorip;
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>同IP站点查询</title>
<style>
*{margin:0;padding:0;}
body{font-size:12px;font-family: Geneva, Arial, Helvetica, sans-serif;}
a img {border:0;}
.red{color:#f00;}
.center{text-align:center;}
p{padding:5px 0 6px 0;word-break:break-all;word-wrap:break-word;}
.f14{font-size:14px;}
a,a:visited{color:#0353ce;}
table {font-size:12px;}
table th {font-size:12px;font-weight:bold;background-color:#f7f7f7;line-height:200%;padding: 0 5px;}
table th {font-size:12px;font-weight:bold;background:#EDF7FF;padding: 0 5px;color:#014198;line-height:200%;}
.red{color:red}
.blue{color:blue}
#footer{line-height:150%;text-align:center;color:#9c9c9c;padding: 8px 0;}
#footer a,#footer a:visited{color:#9c9c9c;}
ul.lst{padding:0;margin:0;width:100%;}
ul.lst li{list-style-type:none;float:left;padding:0 0 0 12px;line-height:24px;height:24px;overflow:hidden;}
ul.lst li{width:258px!important;width:270px;}
</style>
<? if($chaxun_status>0){ ?>
<SCRIPT type="text/javascript">
<!--
var xmlHttp;
function creatXMLHttpRequest() {
if(window.ActiveXObject) {
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
} else if(window.XMLHttpRequest) {
xmlHttp = new XMLHttpRequest();
}
}
function startRequest() {
var queryString;
var domain = "<?=$ip?>";
queryString = "q=" + domain;
creatXMLHttpRequest();
xmlHttp.open("POST","./?action=do","true");
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
xmlHttp.send(queryString);
}
function handleStateChange() {
if(xmlHttp.readyState == 1) {
document.getElementById('ipresult').style.cssText = "";
document.getElementById('ipresult').innerHTML = '<span class="green">结果加载中,请稍等...</span>';
}
if(xmlHttp.readyState == 4) {
if(xmlHttp.status == 200) {
document.getElementById('ipresult').style.cssText = "";
var allcon = xmlHttp.responseText;
document.getElementById('ipresult').innerHTML = allcon;
}
}
}
//-->
</SCRIPT>
<? } ?>
</head>
<body>
<div align="center">
<table cellspacing="4" cellpadding="0" style="background-color:#f7f7f7;border-bottom:1px solid #dfdfdf;" width="778">
<tr>
<td align="left"><a href="/" target="_blank">站长工具</a> > <a href="./" target="_blank">同IP站点查询</a></td>
<td align="right"><a href="javascript:;" onClick="window.external.AddFavorite(document.location.href,document.title);">收藏本页</a></td></tr></table>
<div id="result"><br />
<table width="700" cellpadding="2" cellspacing="0" style="border:1px solid #B2D0EA;">
<tr>
<th align="left"><a href="./" target="_blank">同IP站点查询</a></th>
</tr>
<tr><td align="center">
<table border="0" cellPadding="0" cellSpacing="1">
<tr><td style="font-size:14px">
<br />
<form action="" method="post" name="f1">IP地址或域名 <input name="q" id="q" type="text" size="18" delay="0" value="<? if($chaxun_status>0) echo $q; ?>" style="width:200px;height:22px;font-size:16px;font-family: Geneva, Arial, Helvetica, sans-serif;" /> <input type="submit" value=" 查询 " /></form>
</td></tr></table><br />
</td></tr>
<tr><td align="center" valign="middle" height="40" style="font-size:12px">输入域名或者IP地址,查询同一IP地址的服务器上有哪些网站。</td></tr>
</table>
<br />
<table width="700" cellpadding=2 cellspacing=0 style="border:1px solid #B2D0EA;">
<tr>
<th align="left"><?
if($chaxun_status==1){
echo '<a href="./">'.$title.'</a> > 域名: '.$q;
}elseif($chaxun_status==2){
echo '<a href="./">'.$title.'</a> > IP: '.$ip;
}else{
echo $title;
}
?></th>
</tr>
<tr><td align="left">
<div style="padding:20px">
<p class="f14">
<?
if(!$q){
$ipq = '您的IP地址是:<span class="blue f14">'.$ip.'</span>';
}elseif($chaxun_status == 0){
$ipq = '<b class="red f14">出错啦!</b>没有找到与 <b class="blue f14">'.$q.'</b> 匹配的结果,请确定IP/域名的格式是否写对!</p><p class="f14 blue">你的IP地址是:'.$ip;
}elseif($chaxun_status==1){
$ipq = '你查询的域名 <span class="blue f14">'.$q.'</span></p><p class="f14">域名的IP: <span class="blue f14">'.$ip.'</span>';
}else{
$ipq = "你查询的IP:".$ip;
}
echo $ipq;
?></p><? if($chaxun_status>0){ ?>
<div id="ipresult"></div><script>startRequest();</script>
<? } ?></p><hr style="border-style: dotted;" color="#cccccc" size="1" /><p align="center">相关查询: <A href="../alexa">Alexa查询</A> | <A href="../domain/">域名注册查询</A> | <A href="../whois">Whois查询</A> | <A href="../ip/">IP地址查询</A> | <A href="../pr/pr.php">PR查询</A> | <A href="../weath/">天气预报查询</A> | <A href="../robot">模仿蜘蛛</A> | <A href="/index.php">友情链接查询</A></p>
</div>
</td></tr>
</table><br />
</div>
</div>
<div id="footer">© 2009 <a href="http://tool.111cn.net/">站长工具</a></div>
<div style="display:none;"></div>
</body>
</html>
同IP查询代码下载包
php 获取来路[前一页]页面分析函数本文章提供一款功能全面的获取上一级页面的函数哦,就是来路函数了。
function getref(&$ref,&$fullref) {
global $err,$conf,$HTTP_GET_VARS,$_GET;
if(isset($_GET['anr'])) $refer=$_GET['anr'];
elseif(isset($HTTP_GET_VARS['anr'])) $refer=$HTTP_GET_VARS['anr'];
else $refer='undefined';
if(empty($refer)) $refer='undefined';
if(!strcmp($refer,'null')) $refer='undefined';
$refer=urldecode($refer);
$refer=modsec($refer);
$refer=txtproc($refer);
//to correct back slashes http://111cn.netindex
$refer=str_replace("\","/",$refer);
//to remove unnecessary points http://111cn.net.
$refer=preg_replace("//./",'/',$refer);
$refer=preg_replace("/.//",'/',$refer);
$refer=preg_replace("/.*$/",'',$refer);
$refer=preg_replace("/("|')*$/",'',$refer);
//to remove unnecessary duplicates of slashes http://111cn.net///
$refer=preg_replace("/([^:])(/)+/",'$1/',$refer);
$fullref=$refer;
$refer=preg_replace("/^(https?://)(www.)?/i",'',$refer);
$ref=preg_replace("/[?|&|#|;].*$/i",'',$refer);
$ref=preg_replace("/(/)*$/",'',$ref);
$ref=trim($ref);
$ref=preg_replace("/.*$/",'',$ref);
$ref=preg_replace("/("|')*$/",'',$ref);
$ref=trim($ref);
//check referrer (bad)
if(empty($ref)) $ref='undefined';
//search "." in domain name
if(!preg_match("/^([^./]+.)+([^./])+/i",$ref)) $ref='undefined';
}
}
这是一款可以同时上传10个文件的php+ajax无刷新的上传源码了,并且还带有上传进度条的哦,好了费话不说多了喜欢就来下载吧。<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无刷新文件上传系统</title>
</head>
<body>
<style>
.fu_list {
width:600px;
background:#ebebeb;
font-size:12px;
}
.fu_list td {
padding:5px;
line-height:20px;
background-color:#fff;
}
.fu_list table {
width:100%;
border:1px solid #ebebeb;
}
.fu_list thead td {
background-color:#f4f4f4;
}
.fu_list b {
font-size:14px;
}
/*file容器样式*/
a.files {
width:90px;
height:30px;
overflow:hidden;
display:block;
border:1px solid #BEBEBE;
background:url(img/fu_btn.gif) left top no-repeat;
text-decoration:none;
}
a.files:hover {
background-color:#FFFFEE;
background-position:0 -30px;
}
/*file设为透明,并覆盖整个触发面*/
a.files input {
margin-left:-350px;
font-size:30px;
cursor:pointer;
filter:alpha(opacity=0);
opacity:0;
}
/*取消点击时的虚线框*/
a.files, a.files input {
outline:none;/*ff*/
hide-focus:expression(this.hideFocus=true);/*ie*/
}
</style>
<form id="uploadForm" action="File.php">
<table border="0" cellspacing="1" class="fu_list">
<thead>
<tr>
<td colspan="2"><b>上传文件</b></td>
</tr>
</thead>
<tbody>
<tr>
<td align="right" width="15%" style="line-height:35px;">添加文件:</td>
<td><a href="javascript:void(0);" class="files" id="idFile"></a> <img id="idProcess" style="display:none;" src="img/loading.gif" /></td>
</tr>
<tr>
<td colspan="2"><table border="0" cellspacing="0">
<thead>
<tr>
<td>文件路径</td>
<td width="100"></td>
</tr>
</thead>
<tbody id="idFileList">
</tbody>
</table></td>
</tr>
<tr>
<td colspan="2" style="color:gray">温馨提示:最多可同时上传 <b id="idLimit"></b> 个文件,只允许上传 <b id="idExt"></b> 文件。 </td>
</tr>
<tr>
<td colspan="2" align="center" id="idMsg"><input type="button" value="开始上传" id="idBtnupload" disabled="disabled" />
<input type="button" value="全部取消" id="idBtndel" disabled="disabled" />
</td>
</tr>
</tbody>
</table>
</form>
<script type="text/javascript">
var isIE = (document.all) ? true : false;
var $ = function (id) {
return "string" == typeof id ? document.getElementById(id) : id;
};
var Class = {
create: function() {
return function() {
this.initialize.apply(this, arguments);
}
}
}
var Extend = function(destination, source) {
for (var property in source) {
destination[property] = source[property];
}
}
var Bind = function(object, fun) {
return function() {
return fun.apply(object, arguments);
}
}
var Each = function(list, fun){
for (var i = 0, len = list.length; i < len; i++) { fun(list[i], i); }
};
//文件上传类
var FileUpload = Class.create();
FileUpload.prototype = {
//表单对象,文件控件存放空间
initialize: function(form, folder, options) {
this.Form = $(form);//表单
this.Folder = $(folder);//文件控件存放空间
this.Files = [];//文件集合
this.SetOptions(options);
this.FileName = this.options.FileName;
this._FrameName = this.options.FrameName;
this.Limit = this.options.Limit;
this.Distinct = !!this.options.Distinct;
this.ExtIn = this.options.ExtIn;
this.ExtOut = this.options.ExtOut;
this.onIniFile = this.options.onIniFile;
this.onEmpty = this.options.onEmpty;
this.onNotExtIn = this.options.onNotExtIn;
this.onExtOut = this.options.onExtOut;
this.onLimite = this.options.onLimite;
this.onSame = this.options.onSame;
this.onFail = this.options.onFail;
this.onIni = this.options.onIni;
if(!this._FrameName){
//为每个实例创建不同的iframe
this._FrameName = "uploadFrame_" + Math.floor(Math.random() * 1000);
//ie不能修改iframe的name
var oFrame = isIE ? document.createElement("<iframe name="" + this._FrameName + "">") : document.createElement("iframe");
//为ff设置name
oFrame.name = this._FrameName;
oFrame.style.display = "none";
//在ie文档未加载完用appendChild会报错
document.body.insertBefore(oFrame, document.body.childNodes[0]);
}
//设置form属性,关键是target要指向iframe
this.Form.target = this._FrameName;
this.Form.method = "post";
//注意ie的form没有enctype属性,要用encoding
this.Form.encoding = "multipart/form-data";
//整理一次
this.Ini();
},
//设置默认属性
SetOptions: function(options) {
this.options = {//默认值
FileName: "Files[]",//文件上传控件的name,配合后台使用
FrameName: "",//iframe的name,要自定义iframe的话这里设置name
onIniFile: function(){},//整理文件时执行(其中参数是file对象)
onEmpty: function(){},//文件空值时执行
Limit: 10,//文件数限制,0为不限制
onLimite: function(){},//超过文件数限制时执行
Distinct: true,//是否不允许相同文件
onSame: function(){},//有相同文件时执行
ExtIn: ["gif","jpg","rar","zip","iso","swf","exe"],//允许后缀名
onNotExtIn: function(){},//不是允许后缀名时执行
ExtOut: [],//禁止后缀名,当设置了ExtIn则ExtOut无效
onExtOut: function(){},//是禁止后缀名时执行
onFail: function(){},//文件不通过检测时执行(其中参数是file对象)
onIni: function(){}//重置时执行
};
Extend(this.options, options || {});
},
//整理空间
Ini: function() {
//整理文件集合
this.Files = [];
//整理文件空间,把有值的file放入文件集合
Each(this.Folder.getElementsByTagName("input"), Bind(this, function(o){
if(o.type == "file"){ o.value && this.Files.push(o); this.onIniFile(o); }
}))
//插入一个新的file
var file = document.createElement("input");
file.name = this.FileName; file.type = "file"; file.onchange = Bind(this, function(){ this.Check(file); this.Ini(); });
this.Folder.appendChild(file);
//执行附加程序
this.onIni();
},
//检测file对象
Check: function(file) {
//检测变量
var bCheck = true;
//空值、文件数限制、后缀名、相同文件检测
if(!file.value){
bCheck = false; this.onEmpty();
} else if(this.Limit && this.Files.length >= this.Limit){
bCheck = false; this.onLimite();
} else if(!!this.ExtIn.length && !RegExp(".(" + this.ExtIn.join("|") + ")$", "i").test(file.value)){
//检测是否允许后缀名
bCheck = false; this.onNotExtIn();
} else if(!!this.ExtOut.length && RegExp(".(" + this.ExtOut.join("|") + ")$", "i").test(file.value)) {
//检测是否禁止后缀名
bCheck = false; this.onExtOut();
} else if(!!this.Distinct) {
Each(this.Files, function(o){ if(o.value == file.value){ bCheck = false; } })
if(!bCheck){ this.onSame(); }
}
//没有通过检测
!bCheck && this.onFail(file);
},
//删除指定file
Delete: function(file) {
//移除指定file
this.Folder.removeChild(file); this.Ini();
},
//删除全部file
Clear: function() {
//清空文件空间
Each(this.Files, Bind(this, function(o){ this.Folder.removeChild(o); })); this.Ini();
}
}
var fu = new FileUpload("uploadForm", "idFile", { ExtIn: ["gif","jpg"],
onIniFile: function(file){ file.value ? file.style.display = "none" : this.Folder.removeChild(file); },
onEmpty: function(){ alert("请选择一个文件"); },
onLimite: function(){ alert("超过上传限制"); },
onSame: function(){ alert("已经有相同文件"); },
onNotExtIn: function(){ alert("只允许上传" + this.ExtIn.join(",") + "文件"); },
onFail: function(file){ this.Folder.removeChild(file); },
onIni: function(){
//显示文件列表
var arrRows = [];
if(this.Files.length){
var oThis = this;
Each(this.Files, function(o){
var a = document.createElement("a"); a.innerHTML = "取消"; a.href = "javascript:void(0);";
a.onclick = function(){ oThis.Delete(o); return false; };
arrRows.push([o.value, a]);
});
} else { arrRows.push(["<font color='gray'>没有添加文件</font>", " "]); }
AddList(arrRows);
//设置按钮
$("idBtnupload").disabled = $("idBtndel").disabled = this.Files.length <= 0;
}
});
$("idBtnupload").onclick = function(){
//显示文件列表
var arrRows = [];
Each(fu.Files, function(o){ arrRows.push([o.value, " "]); });
AddList(arrRows);
fu.Folder.style.display = "none";
$("idProcess").style.display = "";
$("idMsg").innerHTML = "正在添加文件到您的网盘中,请稍候……<br />有可能因为网络问题,出现程序长时间无响应,请点击“<a href='?'><font color='red'>取消</font></a>”重新上传文件";
fu.Form.submit();
}
//用来添加文件列表的函数
function AddList(rows){
//根据数组来添加列表
var FileList = $("idFileList"), oFragment = document.createDocumentFragment();
//用文档碎片保存列表
Each(rows, function(cells){
var row = document.createElement("tr");
Each(cells, function(o){
var cell = document.createElement("td");
if(typeof o == "string"){ cell.innerHTML = o; }else{ cell.appendChild(o); }
row.appendChild(cell);
});
oFragment.appendChild(row);
})
//ie的table不支持innerHTML所以这样清空table
while(FileList.hasChildNodes()){ FileList.removeChild(FileList.firstChild); }
FileList.appendChild(oFragment);
}
$("idLimit").innerHTML = fu.Limit;
$("idExt").innerHTML = fu.ExtIn.join(",");
$("idBtndel").onclick = function(){ fu.Clear(); }
//在后台通过window.parent来访问主页面的函数
function Finish(msg){ alert(msg); location.href = location.href; }
</script>
</body>
</html>
file.php文件上传的php源码。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<?
$sort=12;
$f_type=strtolower("swf,jpg,rar,zip,7z,iso,gif");//设置可上传的文件类型
$file_size_max=200*1024*1024;//限制单个文件上传最大容量
$overwrite = 0;//是否允许覆盖相同文件,1:允许,0:不允许
$f_input="Files";//设置上传域名称
foreach($_FILES[$f_input]["error"] as $key => $error){
$up_error="no";
if ($error == UPLOAD_ERR_OK){
$f_name=$_FILES[$f_input]['name'][$key];//获取上传源文件名
$uploadfile=$uploaddir.strtolower(basename($f_name));
$tmp_type=substr(strrchr($f_name,"."),1);//获取文件扩展名
$tmp_type=strtolower($tmp_type);
if(!stristr($f_type,$tmp_type)){
echo "<script>alert('对不起,不能上传".$tmp_type."格式文件, ".$f_name." 文件上传失败!')</script>";
$up_error="yes";
}
if ($_FILES[$f_input]['size'][$key]>$file_size_max) {
echo "<script>alert('对不起,你上传的文件 ".$f_name." 容量为".round($_FILES[$f_input]
['size'][$key]/1024)."Kb,大于规定的".($file_size_max/1024)."Kb,上传失败!')</script>";
$up_error="yes";
}
if (file_exists($uploadfile)&&!$overwrite){
echo "<script>alert('对不起,文件 ".$f_name." 已经存在,上传失败!')</script>";
$up_error="yes";
}
$string = 'abcdefghijklmnopgrstuvwxyz0123456789';
$rand = '';
for ($x=0;$x<12;$x++)
$rand .= substr($string,mt_rand(0,strlen($string)-1),1);
$t=date("ymdHis").substr($gettime[0],2,6).$rand;
$attdir="./file/";
if(!is_dir($attdir))
{ mkdir($attdir);}
$uploadfile=$attdir.$t.".".$tmp_type;
if(($up_error!="yes") and (move_uploaded_file($_FILES[$f_input]['tmp_name']
[$key], $uploadfile))){
$_msg=$_msg.$f_name.'上传成功n';
}
else{
$_msg=$_msg.$f_name.'上传失败n';
}
}
}
echo "<script>window.parent.Finish('".$_msg."');</script>";
?>
</body>
</html>
效果图
function GetContent($type){
if( $type )
{
if(file_exists('./mail_room.html') )
{
$content = file_get_contents( './mail_room.html');
}
else
{
ShowMsg('file can' read fail ');
}
}
else
{
if( file_exists( './mail_person.html') )
{
$content = file_get_contents( './mail_person.html');
}
else
{
ShowMsg('person file read fail!');
}
}
return $content;
}
function template($str)
{
$_url = $_SERVER['HTTP_HOST'];
$_temp = str_replace('{username}',$_SESSION['uname'],$str);
$_temp = str_replace('[bgpic]',getPic(),$_temp);
$_temp = str_replace('{url}',$_url,$_temp);
return $_temp;
}
我们来看看模板文件
<style type="text/css">
#mail{
font-family:"微软雅黑", "宋体",arial;
font-size:12px;
height:530px;
width:662px;
background:url(http://111cn.net/emailimages/mailback.jpg) no-repeat top left;
}
#photo{
height:380px;
width:630px;
position:absolute;
top:20px;
left:25px;
background:url([bgpic]) no-repeat top left;
}
#photo img{
border:none;
height:380px;
width:630px;
}
#infomation{
padding:5px 0 0 0;
position:absolute;
top:400px;
left:25px;
height:105px;
width:629px;
}
#entry{
margin:10px 0 0 6px;
float:left;
width:108px;
height:90px;
}
#entry ul{
margin: 0;
padding: 0;
}
#entry li{
float:left;
list-style:none;
text-indent:10px;
}
#entry a{
display:block;
height:42px;
width:53px;
}
#cjhd{
background:url(http://111cn.net/emailimages/cjhd.gif) no-repeat top left;
height:42px;
width:53px;
}
#aygw{
background:url(http://111cn.net/emailimages/aygw.gif) no-repeat top left;
height:42px;
width:53px;
}
#zdzx{
background:url(http://111cn.net/emailimages/zdzx.gif) no-repeat top left;
height:42px;
width:53px;
}
#title{
height:21px;
margin:5px 0;
background:url(http://111cn.net/emailimages/title.gif) no-repeat top left;
}
#artical{
margin:0 0 0 5px;
float:left;
width:180px;
height:105px;
overflow:hidden;
}
#words{
font-size:14px;
height:70px;
line-height:18px;
margin:20px 0 0 0;
}
#words p{
margin:0;
padding:0;
}
#words a{
text-decoration:underline;
color:#be2f60;
}
#artical{
margin:5px 0 0 0px;
}
#artical ul{
padding:0;
margin:5px 0 0 5px;
}
#artical ul li{
list-style:none;
background:url(111cn.net/emailimages//emailimages/dot.gif) no-repeat 0px 7px;
text-indent:10px;
height:18px;
color:#505050;
float:left;
width:180px;
}
#artical ul li a{
text-decoration:none;
color:#5e5e5e;
}
</style>
</head>
<body>
<div id="mail">
<div id="photo"> </div>
<div id="infomation">
<div id="entry">
<ul>
<li id="cjhd"><a href="#"></a></li>
<li id="zdzx"><a href="#"></a></li>
<li id="aygw"><a href="#"></a></li>
</ul>
</div>
<div id="artical">
<div id="title">
</div>
<ul>
<li><a href="#">新潮食物与儿童疾病的关系 </a></li>
<li><a href="#">不宜喂养宝宝的24种食物 </a></li>
<li><a href="#">育儿饮食错误观点大罗列</a></li>
</ul>
</div>
<div id="words">
<p>{username}说:</p>
<p style="text-indent:20px;"><a href="http://{url}">我发现明星宝宝啦,<br/> 快来一起合影吧!</a></p>
</div>
</div>
</div>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>google分页</title>
<meta name="keywords" content="仿google php分页程序 " />
<meta name="description" content="仿google php分页程序" />
<style type="text/css">
<!--
body { font-family: Arial, Helvetica, sans-serif; font-size: 12px; margin: 0px; padding: 0px; }
div { height: auto; width: 800px; margin: 10px auto; line-height:20px; }
/*CSS manu style pagination*/
.manu {
PADDING-RIGHT: 3px; PADDING-LEFT: 3px; PADDING-BOTTOM: 3px; MARGIN: 3px; PADDING-TOP: 3px; TEXT-ALIGN: center
}
.manu A {
BORDER-RIGHT: #eee 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #eee 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #eee 1px solid; COLOR: #036cb4; PADDING-TOP: 2px; BORDER-BOTTOM: #eee 1px solid; TEXT-DECORATION: none
}
.manu A:hover {
BORDER-RIGHT: #999 1px solid; BORDER-TOP: #999 1px solid; BORDER-LEFT: #999 1px solid; COLOR: #666; BORDER-BOTTOM: #999 1px solid
}
.manu A:active {
BORDER-RIGHT: #999 1px solid; BORDER-TOP: #999 1px solid; BORDER-LEFT: #999 1px solid; COLOR: #666; BORDER-BOTTOM: #999 1px solid
}
.manu .current {
BORDER-RIGHT: #036cb4 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #036cb4 1px solid; PADDING-LEFT: 5px; FONT-WEIGHT: bold; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #036cb4 1px solid; COLOR: #fff; PADDING-TOP: 2px; BORDER-BOTTOM: #036cb4 1px solid; BACKGROUND-COLOR: #036cb4
}
.manu .disabled {
BORDER-RIGHT: #eee 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #eee 1px solid; PADDING-LEFT: 5px; PADDING-BOTTOM: 2px; MARGIN: 2px; BORDER-LEFT: #eee 1px solid; COLOR: #ddd; PADDING-TOP: 2px; BORDER-BOTTOM: #eee 1px solid
}
-->
</style>
</head>
<body>
<?php
require('web_page.php'); //包含分页程序
//数据库配置
$mysql_host = 'localhost'; //数据库服务器
$mysql_user = 'root'; //数据库用户名
$mysql_pass = '123456'; //数据库密码
$mysql_db = 'test'; //数据库名
//连接mysql数据库
$link = mysql_connect($mysql_host,$mysql_user,$mysql_pass) or die ('连接MYSQL服务器出错');
mysql_select_db($mysql_db,$link) or die ('连接MYSQL数据库出错');
//分页开始
$sql_page = "select news_id,news_title from cms_news order by news_id desc";
$sql = mysql_query($sql_page);
$num = mysql_num_rows($sql); //总条数
$max = 1; //每页条数
$pagenum = ceil($num/$max); //可分页数
if(!isset($_GET['page']) or !intval($_GET['page']) or !is_numeric($_GET['page']) or $_GET['page'] > $pagenum){
$page = 1; //当页数不存在 不为十进制数 不是数字 大于可分页数 为1
}else{
$page = $_GET['page']; //当前页数
}
$min = ($page-1)*$max; //当前页从$min条开始
$sql = "{$sql_page} limit $min,$max";
echo '<div>';
if($num){
$sql = mysql_query($sql);
for(;$row = mysql_fetch_array($sql);){
echo '<li><a href="show.php?id='.$row['news_id'].'">'.$row['news_title'].'</a></li>';
}
}else{
echo '<li>暂无</li>';
}
echo '</div>';
//mysql_free_result($sql); //释放资源
?>
<div class="manu"><?php web_page(""); //调用输出分页,引用你的页面其他参数 如:web_page("&class=2&news=6") ?></div>
<?php
//分页结束
mysql_close();
?>
</body>
</html>
上面为调用方法下面为分页程序
<?php
function web_page($pageurl="", $pageselect = true){
global $page,$num,$pagenum; //当前页数 总页数 可分页数
echo "共 $num 条记录,";
$uppage = $page - 1; //上一页
$downpage = $page + 1; //下一页
$lr = 5; //显示多少个页数连接
$left = floor(($lr-1)/2); //左显示多少个页数连接
$right = floor($lr/2); //右显示多少个页数连接
//下面求开始页和结束页
if($page <= $left){ //如果当前页左不足以显示页数
$leftpage = 1;
$rightpage = (($lr<$pagenum)?$lr:$pagenum);
}elseif(($pagenum-$page) < $right){ //如果当前页右不足以显示页数
$leftpage = (($pagenum<$lr)?1:($pagenum-$lr+1));
$rightpage = $pagenum;
}else{ //左右可以显示页数
$leftpage = $page - $left;
$rightpage = $page + $right;
}
//前$lr页和后$lr页
$qianpage = (($page-$lr) < 1?1:($page-$lr));
$houpage = (($page+$lr) > $pagenum?$pagenum:($page+$lr));
//输出分页
if($page != 1){
echo "<a title="首页" href="".$_SERVER['PHP_SELF']."?$pageurl"><<</a> <a title="上一页" href="".$_SERVER['PHP_SELF']."?page=$uppage$pageurl"><</a> ";
}else{
echo "<span class='disabled'><<</span><span class='disabled'><</span> ";
}
for($pages = $leftpage; $pages <= $rightpage; $pages++){
if($pages == $page){
echo "<span class='current'>$pages</span> ";
}else{
echo "<a href="?page=$pages$pageurl">$pages</a> ";
}
}
if($page != $pagenum){
echo "<a title="下一页" href="".$_SERVER['PHP_SELF']."?page=$downpage$pageurl">></a> <a title="末页" href="".$_SERVER['PHP_SELF']."?page=$pagenum$pageurl">>></a>";
}else{
echo "<span class='disabled'>></span><span class='disabled'> >></span> ";
}
//跳转
$javapage = <<<EOM
<script language="javascript">
function web_page(targ,selObj,restore){
eval("self"+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
</script>
EOM;
echo $javapage;
if ($pageselect){
echo "跳转至 <select onchange="web_page('parent',this,0)" name="menu1">";
for($pages = 1; $pages <= $pagenum; $pages++){
$selected = ($pages == $page)?" selected="selected"":"";
echo "<option value="".$_SERVER['PHP_SELF']."?page=$pages$pageurl"$selected> $pages</option>";
}
echo "</select> 页";
}
}
?>
相关文章
- 今天我来给大家介绍在php中跨网站请求伪造的实现方法与最后我们些常用的防止伪造的具体操作方法,有需要了解的朋友可进入参考。 伪造跨站请求介绍 伪造跨站请求...2016-11-25
- 这篇文章主要介绍了Mybatis Plus select 实现只查询部分字段的操作,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2021-09-01
- 有一种方法,可以不打开网站而直接查看到这个网站的源代码.. 这样可以有效地防止误入恶意网站... 在浏览器地址栏输入: view-source:http://...2016-09-20
- <?php require('path.inc.php'); header('content-Type: text/html; charset=utf-8'); $borough_id = intval($_GET['id']); if(!$borough_id){ echo ' ...2016-11-25
- 获取网站icon,常用最简单的方法就是通过website/favicon.ico来获取,不过由于很多网站都是在页面里面设置favicon,所以此方法很多情况都不可用。 更好的办法是通过google提供的服务来实现:http://www.google.com/s2/favi...2014-06-07
- 本文实例讲述了JS基于Mootools实现的个性菜单效果代码。分享给大家供大家参考,具体如下:这里演示基于Mootools做的带动画的垂直型菜单,是一个初学者写的,用来学习Mootools的使用有帮助,下载时请注意要将外部引用的mootools...2015-10-23
- 本文实例讲述了JS+CSS实现分类动态选择及移动功能效果代码。分享给大家供大家参考,具体如下:这是一个类似选项卡功能的选择插件,与普通的TAb区别是加入了动画效果,多用于商品类网站,用作商品分类功能,不过其它网站也可以用,...2015-10-21
- 本文实例讲述了JS实现自定义简单网页软键盘效果。分享给大家供大家参考,具体如下:这是一款自定义的简单点的网页软键盘,没有使用任何控件,仅是为了练习JavaScript编写水平,安全性方面没有过多考虑,有顾虑的可以不用,目的是学...2015-11-08
- php 取除连续空格与换行代码,这些我们都用到str_replace与正则函数 第一种: $content=str_replace("n","",$content); echo $content; 第二种: $content=preg_replac...2016-11-25
MyBatisPlus-QueryWrapper多条件查询及修改方式
这篇文章主要介绍了MyBatisPlus-QueryWrapper多条件查询及修改方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2022-06-27- php简单用户登陆程序代码 这些教程很对初学者来讲是很有用的哦,这款就下面这一点点代码了哦。 <center> <p> </p> <p> </p> <form name="form1...2016-11-25
- 公司一些wordpress网站由于下载的插件存在恶意代码,导致整个服务器所有网站PHP文件都存在恶意代码,就写了个简单的脚本清除。恶意代码示例...2015-10-23
- 这篇文章主要介绍了Oracle使用like查询时对下划线的处理方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-03-16
- 本文实例讲述了JS实现双击屏幕滚动效果代码。分享给大家供大家参考,具体如下:这里演示双击滚屏效果代码的实现方法,不知道有觉得有用处的没,现在网上还有很多还在用这个特效的呢,代码分享给大家吧。运行效果截图如下:在线演...2015-10-30
- 其实挺简单的就是if(navigator.userAgent.indexOf('UCBrowser') > -1) {alert("uc浏览器");}else{//不是uc浏览器执行的操作}如果想测试某个浏览器的特征可以通过如下方法获取JS获取浏览器信息 浏览器代码名称:navigator...2015-11-08
- 这篇文章主要介绍了解决mybatis-plus 查询耗时慢的问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2021-07-04
- 一、日期减去天数等于第二个日期function cc(dd,dadd){//可以加上错误处理var a = new Date(dd)a = a.valueOf()a = a - dadd * 24 * 60 * 60 * 1000a = new Date(a)alert(a.getFullYear() + "年" + (a.getMonth() +...2015-11-08
- 微信支付,即便交了保证金,你还是处理测试阶段,不能正式发布。必须到你通过程序测试提交订单、发货通知等数据到微信的系统中,才能申请发布。然后,因为在微信中是通过JS方式调用API,必须在微信后台设置支付授权目录,而且要到...2014-05-31
mac下Apache + MySql + PHP搭建网站开发环境
首先为什不自己分别搭建Apache,PHP和MySql的环境呢?这样自己可以了解更多知识,说起来也更酷。可也许因为我懒吧,我是那种“既然有现成的,用就是了”的人。君子生非异也,善假于物也。两千年前的荀子就教导我们,要善于利用工具...2014-06-07- 本文实例讲述了PHP常用的小程序代码段。分享给大家供大家参考,具体如下:1.计算两个时间的相差几天$startdate=strtotime("2009-12-09");$enddate=strtotime("2009-12-05");上面的php时间日期函数strtotime已经把字符串...2015-11-24