php 域名处理函数

 更新时间:2016年11月25日 16:03  点击:1384
php 域名处理函数

下面这款个一个是判断输入的域名是不是合法的,然后再把http,https,ftp进行处理,分析再发送

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 = '/';
   }

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;
}

php 设置cookie高级用法

function getvis(&$pagesid,&$retime) {
  global $err,$conf,$HTTP_COOKIE_VARS,$_COOKIE;

  if(isset($_COOKIE['ant'])) $cot=$_COOKIE['ant'];
  elseif(isset($HTTP_COOKIE_VARS['ant'])) $cot=$HTTP_COOKIE_VARS['ant'];
  else $cot='';
  $cos=preg_split("/x/",$cot);
  $max=sizeof($cos);
  for($c=0;$c<$max;$c++) {
    if(strlen($cos[$c])==10) {
      $id=substr($cos[$c],0,2);
      eval("$id=0x$id;");
      $anct[$id]=$cos[$c];
    }
  }

  if(isset($_COOKIE['anm'])) $com=$_COOKIE['anm'];
  elseif(isset($HTTP_COOKIE_VARS['anm'])) $com=$HTTP_COOKIE_VARS['anm'];
  else $com='';
  $cos=preg_split("/x/",$com);
  $max=sizeof($cos);
  for($c=0;$c<$max;$c++) {
    if(strlen($cos[$c])==10) {
      $id=substr($cos[$c],0,2);
      eval("$id=0x$id;");
      $tim=substr($cos[$c],2,8);
      eval("$tim=0x$tim;");
      if($tim>=$conf->mtime) $ancm[$id]=$cos[$c];
    }
  }

  if(isset($_COOKIE['anw'])) $cow=$_COOKIE['anw'];
  elseif(isset($HTTP_COOKIE_VARS['anw'])) $cow=$HTTP_COOKIE_VARS['anw'];
  else $cow='';
  $cos=preg_split("/x/",$cow);
  $max=sizeof($cos);
  for($c=0;$c<$max;$c++) {
    if(strlen($cos[$c])==10) {
      $id=substr($cos[$c],0,2);
      eval("$id=0x$id;");
      $tim=substr($cos[$c],2,8);
      eval("$tim=0x$tim;");
      if($tim>=$conf->wtime) $ancw[$id]=$cos[$c];
    }
  }

  if(isset($_COOKIE['an1'])) $co1=$_COOKIE['an1'];
  elseif(isset($HTTP_COOKIE_VARS['an1'])) $co1=$HTTP_COOKIE_VARS['an1'];
  else $co1='';
  $cos=preg_split("/x/",$co1);
  $max=sizeof($cos);
  for($c=0;$c<$max;$c++) {
    if(strlen($cos[$c])==10) {
      $id=substr($cos[$c],0,2);
      eval("$id=0x$id;");
      $tim=substr($cos[$c],2,8);
      eval("$tim=0x$tim;");
      if($tim>=$conf->dtime) $anc1[$id]=$cos[$c];
    }
  }

  //current time in HEX
  if($conf->ctime>0x7FFFFFFF) {
    $t1=$conf->ctime/16;
    $t2=$conf->ctime&0xF;
    $ctimestr=sprintf("%07X%01X",$t1,$t2);
  }
  else {
    $ctimestr=sprintf("%08X",$conf->ctime);
  }

  reset($pagesid);
  while($e=each($pagesid)) {
    $k=$e[0];
    if(isset($anct[$k])) {
      $pagesid[$k].='|0';
      if(strlen($anct[$k])==10) {
        $tim=substr($anct[$k],2,8);
        eval("$tim=0x$tim;");
        $retime[$k]=$tim;
      }
    }
    else {
      $pagesid[$k].='|1';
      $anct[$k]=sprintf("%02X%s",$k,$ctimestr);
    }

    if(isset($ancm[$k])) $pagesid[$k].='|0';
    else {
      $pagesid[$k].='|1';
      $ancm[$k]=sprintf("%02X%s",$k,$ctimestr);
    }

    if(isset($ancw[$k])) $pagesid[$k].='|0';
    else {
      $pagesid[$k].='|1';
      $ancw[$k]=sprintf("%02X%s",$k,$ctimestr);
    }

    if(isset($anc1[$k])) $pagesid[$k].='|0';
    else {
      $pagesid[$k].='|1';
      $anc1[$k]=sprintf("%02X%s",$k,$ctimestr);
    }
  }

  $cot=join('x',$anct);
  $com=join('x',$ancm);
  $cow=join('x',$ancw);
  $co1=join('x',$anc1);

  //get path
  $path=$conf->url;
  $path=preg_replace("/^(http://)([^/]+)/i",'',$path);
  $path.='aa.php';
  //set cookie
  SetCookie('ant',$cot,time()+($conf->time1*3000),$path);
  SetCookie('anm',$com,time()+($conf->time1*31),$path);
  SetCookie('anw',$cow,time()+($conf->time1*7),$path);
  SetCookie('an1',$co1,time()+$conf->time1,$path);
}

php 读取远程网站内容[反盗连]

这是一款利用php fsockopen来读取远程服务器的内容哦,下面这段程序的做法就是可以反盗连呢,好了下面来看看吧。

 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);
       }
   }
}

php数据分页加数据显示效果

<?php
include_once(dirname(__FILE__).'../../Inc/Conn.php');
include_once(dirname(__FILE__).'../../photo/Inc/function.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>
<style type="text/css">
<!--
body,td,th {
 font-size: 12px;
 height:17px;
 padding:8px 0px 0px 0px;
 text-align:center;
 
}
body {
 margin-left: 0px;
 margin-top: 10px;
 margin-right: 0px;
 margin-bottom: 0px;
}
td{
 border:1px solid #333;
 }

-->
</style></head>

<body>
<div style="height:26px;text-align:left; width:98%;font-size:16px; font-weight:bold; margin:0px auto;"><a href="export.php" target="_blank">导出Execel表格</a></div>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="8%"><strong>帐号</strong></td>
    <td width="14%"><strong>邮箱</strong></td>
    <td width="5%"><strong>性别</strong></td>
    <td width="9%"><strong>宝宝出生日期</strong></td>
    <td width="12%"><strong>省份</strong></td>
    <td width="9%"><strong>真实姓名</strong></td>
    <td width="12%"><strong>邮编</strong></td>
    <td width="10%"><strong>手机</strong></td>
    <td width="21%"><strong>地址</strong></td>
  </tr>
  <?php

    $sql  ="Select * from tablename";
  
    $result =mysql_query($sql) or die('fail1'.mysql_error());
    $rs  =mysql_fetch_array($result);
    $rdcount =mysql_num_rows($result);
    if($rdcount){
    $pagesize =20;
    $pagecount=($rdcount % $pagesize)?(int)($rdcount / $pagesize)+1:$rdcount/$pagesize;//统计总页面
    $page  =isset($_GET['page'])?$_GET['page']:1;//取得当前页面
    $start =($page>=1 && $page<=$pagecount)?$start=$pagesize*($page-1):$start=1;//取得超始记录
    $start =$start;
    $sql  =$sql." order by add_date desc limit $start,$pagesize";
       
    $result =mysql_query($sql) or die(mysql_error());
  while($rs =mysql_fetch_array($result) ){    
   echo"<tr>
    <td>".$rs['User_Name']."</td>
    <td>".$rs['User_Mail']."</td>
    <td>".$rs['User_Baby_Sex']."</td>
    <td>".$rs['User_Baby_Birth']."&nbsp;</td>
    <td>".$rs['sheng']." &nbsp;</td>
    <td>".$rs['User_rname']." &nbsp;</td>
    <td>".$rs['User_Zip']." &nbsp;</td>
    <td>".$rs['User_Hand']." &nbsp;</td>
    <td>".$rs['User_Address']." &nbsp;</td>
     </tr>
     ";
  
  }
  echo "<tr> <td colspan=9>";
 pagelist1($page,$pagecount,$rdcount,'?page=',$pagesize);
 echo "</td> </tr> ";
 }else{
   echo '暂时没有信息!';
 }


function pagelist1($page,$pagecount,$totalrecord,$url,$pagesize)

 if($page=="" || $page>$pagecount)
 {
  $page=1;
 }
 echo("记录".$totalrecord."条 每页".$pagesize."条 共".$pagecount."页 <a href=".$url."1>&nbsp;<<</a>&nbsp; ");
 if($page>1)
 { 
  echo("<a href=".$url.($page-1).">&nbsp;<&nbsp;</a> ");
 }  
 if($page+9>$pagecount)
 {
  $current = $pagecount; 
 }
 else
 { 
  $current = $page+9; 
 } 
 for($i=$page;$i<=$current;$i++)
 { 
  echo("<a href=".$url."$i class='sf'>$i</a> ");
 }
 if($pagecount>$page)
 {
  echo("<a href=".$url.($page+1).">&nbsp;>&nbsp;</a> ");
 } 
  echo("<a href=".$url.$pagecount.">&nbsp;>></a> ");
}
  ?>
 
</table>
</body>
</html>

php导出mysql成cvs execel表

<?php
include_once(dirname(__FILE__).'../../Inc/Conn.php');
include_once(dirname(__FILE__).'../../photo/Inc/function.php');
$Date = date("Y-m-d");
$Filename = $Date.'_'.date("h_i_s").".csv";

$a = "帐号,邮箱,性别,宝宝出生日期,省份,真实姓名,邮编,手机,地址 rn";
header("Content-type:application/vnd.ms-excel");
header("Content-Disposition:filename=".$Filename);
$Sql = "Select * from oy_use";
$Result = mysql_query($Sql) or die(mysql_error());
  while($rs = mysql_fetch_array($Result) ){
   // if(get_days($rs['m_time'])<= $Table ){
   $a.=$rs['User_Name'].','. $rs['User_Mail'].",".($rs['User_Baby_Sex']?'男':'女').",". $rs['User_Baby_Birth'].",";
   $a.="".$rs['sheng'].",". $rs['User_rname'].",".$rs['User_Zip'].",".$rs['User_Hand'].",".$rs['User_Address']." rn ";
 //  }
  } 
  echo $a;

 
    
function get_days($base){

 $Date_1=date("Y-m-d");//格式也可以是:$Date_1="2003-6-25 23:29:14";
 
 $Date_2=substr($base,0,10);  
 
 $Date_List_a1=explode("-",$Date_1);
 
 $Date_List_a2=explode("-",$Date_2);
 //print_r($Date_List_a2);
 
 $d1=mktime(0,0,0,$Date_List_a1[1],$Date_List_a1[2],$Date_List_a1[0]);
 
 $d2=mktime(0,0,0,$Date_List_a2[1],$Date_List_a2[2],$Date_List_a2[0]);
 //echo round(($d1-$d2)/3600/24),'<br>';
 return round(($d1-$d2)/3600/24);


}
?>

[!--infotagslink--]

相关文章

  • php正确禁用eval函数与误区介绍

    eval函数在php中是一个函数并不是系统组件函数,我们在php.ini中的disable_functions是无法禁止它的,因这他不是一个php_function哦。 eval()针对php安全来说具有很...2016-11-25
  • php中eval()函数操作数组的方法

    在php中eval是一个函数并且不能直接禁用了,但eval函数又相当的危险了经常会出现一些问题了,今天我们就一起来看看eval函数对数组的操作 例子, <?php $data="array...2016-11-25
  • Python astype(np.float)函数使用方法解析

    这篇文章主要介绍了Python astype(np.float)函数使用方法解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-06-08
  • Python中的imread()函数用法说明

    这篇文章主要介绍了Python中的imread()函数用法说明,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-16
  • C# 中如何取绝对值函数

    本文主要介绍了C# 中取绝对值的函数。具有很好的参考价值。下面跟着小编一起来看下吧...2020-06-25
  • C#学习笔记- 随机函数Random()的用法详解

    下面小编就为大家带来一篇C#学习笔记- 随机函数Random()的用法详解。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...2020-06-25
  • Windows批量搜索并复制/剪切文件的批处理程序实例

    这篇文章主要介绍了Windows批量搜索并复制/剪切文件的批处理程序实例,需要的朋友可以参考下...2020-06-30
  • 金额阿拉伯数字转换为中文的自定义函数

    CREATE FUNCTION ChangeBigSmall (@ChangeMoney money) RETURNS VarChar(100) AS BEGIN Declare @String1 char(20) Declare @String2 char...2016-11-25
  • Android开发中findViewById()函数用法与简化

    findViewById方法在android开发中是获取页面控件的值了,有没有发现我们一个页面控件多了会反复研究写findViewById呢,下面我们一起来看它的简化方法。 Android中Fin...2016-09-20
  • C++中 Sort函数详细解析

    这篇文章主要介绍了C++中Sort函数详细解析,sort函数是algorithm库下的一个函数,sort函数是不稳定的,即大小相同的元素在排序后相对顺序可能发生改变...2022-08-18
  • BAT批处理判断服务是否正常运行的方法(批处理命令综合应用)

    批处理就是对某对象进行批量的处理,通常被认为是一种简化的脚本语言,它应用于DOS和Windows系统中。这篇文章主要介绍了BAT批处理判断服务是否正常运行(批处理命令综合应用),需要的朋友可以参考下...2020-06-30
  • PHP用strstr()函数阻止垃圾评论(通过判断a标记)

    strstr() 函数搜索一个字符串在另一个字符串中的第一次出现。该函数返回字符串的其余部分(从匹配点)。如果未找到所搜索的字符串,则返回 false。语法:strstr(string,search)参数string,必需。规定被搜索的字符串。 参数sea...2013-10-04
  • PHP函数分享之curl方式取得数据、模拟登陆、POST数据

    废话不多说直接上代码复制代码 代码如下:/********************** curl 系列 ***********************///直接通过curl方式取得数据(包含POST、HEADER等)/* * $url: 如果非数组,则为http;如是数组,则为https * $header:...2014-06-07
  • php中的foreach函数的2种用法

    Foreach 函数(PHP4/PHP5)foreach 语法结构提供了遍历数组的简单方式。foreach 仅能够应用于数组和对象,如果尝试应用于其他数据类型的变量,或者未初始化的变量将发出错误信息。...2013-09-28
  • C语言中free函数的使用详解

    free函数是释放之前某一次malloc函数申请的空间,而且只是释放空间,并不改变指针的值。下面我们就来详细探讨下...2020-04-25
  • PHP函数strip_tags的一个bug浅析

    PHP 函数 strip_tags 提供了从字符串中去除 HTML 和 PHP 标记的功能,该函数尝试返回给定的字符串 str 去除空字符、HTML 和 PHP 标记后的结果。由于 strip_tags() 无法实际验证 HTML,不完整或者破损标签将导致更多的数...2014-05-31
  • PHP file_get_contents设置超时处理方法

    file_get_contents的超时处理话说,从PHP5开始,file_get_content已经支持context了(手册上写着:5.0.0 Added the context support. ),也就是说,从5.0开始,file_get_contents其实也可以POST数据。今天说的这篇是讲超时的,确实在...2013-10-04
  • SQL Server中row_number函数的常见用法示例详解

    这篇文章主要给大家介绍了关于SQL Server中row_number函数的常见用法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-12-08
  • C#多线程中的异常处理操作示例

    这篇文章主要介绍了C#多线程中的异常处理操作,涉及C#多线程及异常的捕获、处理等相关操作技巧,需要的朋友可以参考下...2020-06-25
  • PHP加密解密函数详解

    分享一个PHP加密解密的函数,此函数实现了对部分变量值的加密的功能。 加密代码如下: /* *功能:对字符串进行加密处理 *参数一:需要加密的内容 *参数二:密钥 */ function passport_encrypt($str,$key){ //加密函数 srand(...2015-10-30