php mongodb操作类,适合mongodb2.x和mongodb3.x

php 通用redis类 不指定

jed , 2018-3-14 11:47 , 代码编程 , 评论(0) , 阅读(46597) , Via 本站原创
php 通用redis类
下载文件 (已下载 773 次)

Mongodb PHP封装类 不指定

jed , 2018-3-14 11:46 , 代码编程 , 评论(0) , 阅读(51381) , Via 本站原创
Mongodb PHP封装类

PHP生成excel和word 不指定

jed , 2018-3-14 11:40 , 代码编程 , 评论(0) , 阅读(50130) , Via 本站原创
PHP生成excel和word

伪造来源采集http.php 不指定

jed , 2018-3-14 11:22 , 代码编程 , 评论(0) , 阅读(40519) , Via 本站原创

<?php
    function http($url){
    $ch = curl_init();  
    $curlurl = $url;  
    $referurl = $url;  
    $ip=mt_rand(11, 191).".".mt_rand(0, 240).".".mt_rand(1, 240).".".mt_rand(1, 240);   //随机ip  
    $agentarry=[  
      //PC端的UserAgent  
      "safari 5.1 – MAC"=>"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11",  
      "safari 5.1 – Windows"=>"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50",  
      "Firefox 38esr"=>"Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Firefox/38.0",  
      "IE 11"=>"Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; InfoPath.3; rv:11.0) like Gecko",  
      "IE 9.0"=>"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0",  
      "IE 8.0"=>"Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)",  
      "IE 7.0"=>"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)",  
      "IE 6.0"=>"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",  
      "Firefox 4.0.1 – MAC"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1",  
      "Firefox 4.0.1 – Windows"=>"Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1",  
      "Opera 11.11 – MAC"=>"Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11",  
      "Opera 11.11 – Windows"=>"Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11",  
      "Chrome 17.0 – MAC"=>"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11",  
      "傲游(Maxthon)"=>"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)",  
      "腾讯TT"=>"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)",  
      "世界之窗(The World) 2.x"=>"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)",  
      "世界之窗(The World) 3.x"=>"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)",  
      "360浏览器"=>"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)",  
      "搜狗浏览器 1.x"=>"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; SE 2.X MetaSr 1.0; SE 2.X MetaSr 1.0; .NET CLR 2.0.50727; SE 2.X MetaSr 1.0)",  
      "Avant"=>"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)",  
      "Green Browser"=>"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)",  
      //移动端口  
      "safari iOS 4.33 – iPhone"=>"Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5",  
      "safari iOS 4.33 – iPod Touch"=>"Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5",  
      "safari iOS 4.33 – iPad"=>"Mozilla/5.0 (iPad; U; CPU OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5",  
      "Android N1"=>"Mozilla/5.0 (Linux; U; Android 2.3.7; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1",  
      "Android QQ浏览器 For android"=>"MQQBrowser/26 Mozilla/5.0 (Linux; U; Android 2.3.7; zh-cn; MB200 Build/GRJ22; CyanogenMod-7) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1",  
      "Android Opera Mobile"=>"Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10",  
      "Android Pad Moto Xoom"=>"Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13",  
      "BlackBerry"=>"Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+",  
      "WebOS HP Touchpad"=>"Mozilla/5.0 (hp-tablet; Linux; hpwOS/3.0.0; U; en-US) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/233.70 Safari/534.6 TouchPad/1.0",  
      "UC标准"=>"NOKIA5700/ UCWEB7.0.2.37/28/999",  
      "UCOpenwave"=>"Openwave/ UCWEB7.0.2.37/28/999",  
      "UC Opera"=>"Mozilla/4.0 (compatible; MSIE 6.0; ) Opera/UCWEB7.0.2.37/28/999",  
      "微信内置浏览器"=>"Mozilla/5.0 (Linux; Android 6.0; 1503-M02 Build/MRA58K) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/37.0.0.0 Mobile MQQBrowser/6.2 TBS/036558 Safari/537.36 MicroMessenger/6.3.25.861 NetType/WIFI Language/zh_CN",  
       // ""=>"",  
      
    ];  
    //$useragent="Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11";  //要得到类似这样useranget 可以自定义  
    $useragent=$agentarry[array_rand($agentarry,1)];  //随机浏览器useragent  
    $header = array(  
      'CLIENT-IP:'.$ip,  
      'X-FORWARDED-FOR:'.$ip,  
    );    //构造ip  
    curl_setopt($ch, CURLOPT_URL, $curlurl); //要抓取的网址  
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);  
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);  
    curl_setopt($ch, CURLOPT_REFERER, $referurl);  //模拟来源网址  
    curl_setopt($ch, CURLOPT_USERAGENT, $useragent); //模拟常用浏览器的useragent  
      
    $page_content = curl_exec($ch);  
    curl_close($ch);  
    return $page_content;  
  }

PHP的FTP操作类 不指定

jed , 2018-3-14 11:20 , 代码编程 , 评论(0) , 阅读(31768) , Via 本站原创

<?php
/**
* 作用:FTP操作类( 拷贝、移动、删除文件/创建目录 )
*/
class class_ftp
{
    public $off; // 返回操作状态(成功/失败)
    public $conn_id; // FTP连接
    const FTP_HOST='*.*.*.*';
    const FTP_PORT='21';
    const FTP_USER='*******';
    const FTP_PASS='*******';
    /**
    * 方法:FTP连接
    * @FTP_HOST -- FTP主机
    * @FTP_PORT -- 端口
    * @FTP_USER -- 用户名
    * @FTP_PASS -- 密码
    */
    function __construct()
    {
    $this->conn_id = @ftp_connect(self::FTP_HOST,self::FTP_PORT) or die("FTP服务器连接失败");
    @ftp_login($this->conn_id,self::FTP_USER,self::FTP_PASS) or die("FTP服务器登陆失败");
    @ftp_pasv($this->conn_id,1); // 打开被动模拟
    }
    /**
    * 方法:上传文件
    * @path -- 本地路径
    * @newpath -- 上传路径
    * @type -- 若目标目录不存在则新建
     */
     function up_file($path,$newpath,$type=true)
     {
     var_dump($this->conn_id);exit;
     if($type) $this->dir_mkdirs($newpath);
     $this->off = @ftp_put($this->conn_id,$newpath,$path,FTP_BINARY);
     if(!$this->off) echo "文件上传失败,请检查权限及路径是否正确!";
     }
     /**
     * 方法:移动文件
     * @path -- 原路径
     * @newpath -- 新路径
     * @type -- 若目标目录不存在则新建
     */
     function move_file($path,$newpath,$type=true)
     {
     if($type) $this->dir_mkdirs($newpath);
     $this->off = @ftp_rename($this->conn_id,$path,$newpath);
     if(!$this->off) echo "文件移动失败,请检查权限及原路径是否正确!";
     }
     /**
     * 方法:复制文件
     * 说明:由于FTP无复制命令,本方法变通操作为:下载后再上传到新的路径
     * @path -- 原路径
     * @newpath -- 新路径
     * @type -- 若目标目录不存在则新建
     */
     function copy_file($path,$newpath,$type=true)
     {
     $downpath = "c:/tmp.dat";
     $this->off = @ftp_get($this->conn_id,$downpath,$path,FTP_BINARY);// 下载
     if(!$this->off) echo "文件复制失败,请检查权限及原路径是否正确!";
     $this->up_file($downpath,$newpath,$type);
     }
     /**
     * 方法:删除文件
     * @path -- 路径
     */
     function del_file($path)
     {
     $this->off = @ftp_delete($this->conn_id,$path);
     if(!$this->off) echo "文件删除失败,请检查权限及路径是否正确!";
     }
     /**
     * 方法:生成目录
     * @path -- 路径
     */
     function dir_mkdirs($path)
     {
     $path_arr = explode('/',$path); // 取目录数组
     $file_name = array_pop($path_arr); // 弹出文件名
     $path_div = count($path_arr); // 取层数
     foreach($path_arr as $val) // 创建目录
      {
      if(@ftp_chdir($this->conn_id,$val) == FALSE)
      {
      $tmp = @ftp_mkdir($this->conn_id,$val);
      if($tmp == FALSE)
      {
      echo "目录创建失败,请检查权限及路径是否正确!";
      exit;
     }
     @ftp_chdir($this->conn_id,$val);
     }
     }
     for($i=1;$i=$path_div;$i++) // 回退到根
     {
     @ftp_cdup($this->conn_id);
     }
     }
     /**
     * 方法:关闭FTP连接
         */
             function close()
             {
             @ftp_close($this->conn_id);
     }
     }// class class_ftp end
    
     /************************************** 测试 ***********************************
     $ftp = new class_ftp('192.168.100.143',21,'user','pwd'); // 打开FTP连接
     //$ftp->up_file('aa.txt','a/b/c/cc.txt'); // 上传文件
     //$ftp->move_file('a/b/c/cc.txt','a/cc.txt'); // 移动文件
     //$ftp->copy_file('a/cc.txt','a/b/dd.txt'); // 复制文件
     //$ftp->del_file('a/b/dd.txt'); // 删除文件
     $ftp->close(); // 关闭FTP连接
     ******************************************************************************/
?>

<?php
header("Content-type:text/html;charset=utf-8");


/**
* 程序说明:php记录所有post,get,cookie以及IP地址,来路,访问网址
* @author    yujianyue <admin@ewuyi.net>
* @homepage  http://12391.net
*/


//记录得到的
function slog($rr,$StrValue) {
  $logfile = fopen($rr,'a+');
  fwrite($logfile,"\r\n".$StrValue);
  fclose($logfile);
}

function arraforeach($arr) {
  static $str;
  static $keystr;
  if (!is_array($arr)) {
  return $arr;
  }
  foreach ($arr as $key => $val ) {
  $keystr=$keystr.$key;
  if (is_array($val)) {
  arraforeach($val);
  } else {
  $str[] = $val.$keystr;
  }
  }
  return implode($str);
}

function rlog($StrKey,$StrValue,$ArrReq,$method) {
  $StrValue=arraforeach($StrValue);
  return  "<tr><td>$method</td><td>$StrKey</td><td>$StrValue</td></tr>\r\n";
}

$linev = "<h1>".date('Y-m-d H:i:s')."</h1>\r\n";
$linev .= "<table>\r\n";

//逐个GET
  foreach($_GET as $key=>$value) {
$linev .= "\r\n".rlog($key,$value,$getfilter,"GET");
  }

//逐个POST
  foreach($_POST as $key=>$value) {
$linev .= "\r\n".rlog($key,$value,$postfilter,"POST");
  }

//逐个COOKIE
  foreach($_COOKIE as $key=>$value) {
$linev .= "\r\n".rlog($key,$value,$cookiefilter,"COOKIE");
  }

//尝试记录RAW等POST过来的xml,json数据
  $datainput = file_get_contents('php://input');
  if($datainput){
  $datainput=arraforeach($datainput);
$linev .= "\r\n".rlog("Input",$datainput,$datainput,"Input");
  }else{
  $datainput = $GLOBALS['HTTP_RAW_POST_DATA'];
  $datainput = arraforeach($datainput);
if($datainput) $linev .= "\r\n".rlog("Input",$datainput,$datainput,"RAW_POST");
  }

/*
$linev .=  "\r\n MYIP-=>".$_SERVER["REMOTE_ADDR"]."\r\n";
$linev .=  " From-=>".$_SERVER['HTTP_REFERER']."\r\n";
$linev .=  " Uurl-=>".$_SERVER["REQUEST_URI"]."\r\n";
$linev .=  " Agen-=>".$_SERVER['HTTP_USER_AGENT']."\r\n\r\n";
*/

$linev .=  "\r\n".rlog("From",$_SERVER['HTTP_REFERER'],$_SERVER['HTTP_REFERER'],"From");
$linev .=  "\r\n".rlog("Uurl",$_SERVER["REQUEST_URI"],$_SERVER["REQUEST_URI"],"Uurl");
$linev .=  "\r\n".rlog("MYIP",$_SERVER["REMOTE_ADDR"],$_SERVER["REMOTE_ADDR"],"MYIP");
$linev .=  "\r\n".rlog("Agen",$_SERVER['HTTP_USER_AGENT'],$_SERVER['HTTP_USER_AGENT'],"Agen");
$linev .=  "\r\n</table>\r\n";


$lines='<style type="text/css">table{border:1px solid #0180CF; margin:0 auto;font-size:12px;width:92%;}table td{border:1px solid #a2c6d3;padding:5px;word-wrap:break-word;word-break:break-all;}</style>';

$rr = './_12391.net_'.date('Y-m-d').'.html';//按天存放

if(!file_exists($rr)){
slog($rr,$lines);
}

slog($rr,$linev);
echo $lines;
echo $linev;


?>

PHP是否命令行执行 不指定

jed , 2018-3-14 11:13 , 代码编程 , 评论(0) , 阅读(18694) , Via 本站原创

<?php
function is_cli()
{
    return preg_match("/cli/i", php_sapi_name()) ? true : false;
}


<?php

function getRedis()
{
    $redis = new Redis();
    $redis->connect('127.0.0.1', 6379);
    return $redis;
}

function getApiLimit($api, $default = '2000')
{
    //接口名称 = 每次请求ms间隔
    $info = [
        'user.info' => '500',
        'user.login' => '1000'
    ];
    return isset($info[$api]) ? $info[$api] : $default;
}

$api = isset($_GET['path']) ? $_GET['path'] : 'main';
$time = getApiLimit($api);
$key = "api_limit_" . $api;
$redis = getRedis();
$num = $redis->incr($key);
if($num == 1) {
    $redis->pExpire($key, $time);
} else {
    exit('api limit');
}
echo 'success';

PHP+Crontab执行定时任务 不指定

jed , 2018-3-14 10:40 , 服务器技术 , 评论(0) , 阅读(13196) , Via 本站原创
我们做web项目开发的,经常会需要定时备份数据,定时执行重启某个服务或者定时执行某个PHP程序等等,一般在Linux下使用Crontab,在Windows下使用计划任务。本文主要介绍Linux下使用Crontab基础知识以及执行PHP任务。

Crontab是一个Unix/Linux系统下的常用的定时执行工具,可以在无需人工干预的情况下运行指定作业。
分页: 8/81 第一页 上页 3 4 5 6 7 8 9 10 11 12 下页 最后页 [ 显示模式: 摘要 | 列表 ]