首页
关于
Search
1
给你10个市场数据调研报告的免费下载网站!以后竞品数据就从这里找!
182 阅读
2
php接口优化 使用curl_multi_init批量请求
144 阅读
3
《从菜鸟到大师之路 ElasticSearch 篇》
107 阅读
4
2024年备考系统架构设计师
104 阅读
5
PHP 文件I/O
92 阅读
php
thinkphp
laravel
工具
开源
mysql
数据结构
总结
思维逻辑
令人感动的创富故事
读书笔记
前端
vue
js
css
书籍
开源之旅
架构
消息队列
docker
教程
代码片段
redis
服务器
nginx
linux
科普
java
c
ElasticSearch
测试
php进阶
php基础
登录
Search
标签搜索
php函数
php语法
性能优化
安全
错误和异常处理
问题
vue
Composer
Session
缓存
框架
Swoole
api
并发
异步
正则表达式
php-fpm
mysql 索引
开发规范
协程
dafenqi
累计撰写
786
篇文章
累计收到
28
条评论
首页
栏目
php
thinkphp
laravel
工具
开源
mysql
数据结构
总结
思维逻辑
令人感动的创富故事
读书笔记
前端
vue
js
css
书籍
开源之旅
架构
消息队列
docker
教程
代码片段
副业
redis
服务器
nginx
linux
科普
java
c
ElasticSearch
测试
php进阶
php基础
页面
关于
搜索到
138
篇与
的结果
2023-08-07
php上传类(安全上传类)
php上传类(安全上传类)<?php //php文件上传类 //author: lenix 2014.10.7<!--more--> header("Content-Type:text/html; charset=utf-8"); date_default_timezone_set("Asia/Shanghai"); class UploadFile { private $imageType=["image/gif","image/jpeg","image/jpg","image/png","image/x-png","image/bmp","image/x-ms-bmp","image/pjpeg"];//图片类型 private $fileType=["application/zip","application/msexcel","application/xml","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/mspowerpoint","application/vnd.ms-powerpoint","application/pdf","application/x-shockwave-flash","application/x-rar-compressed","application/x-rar","audio/mpeg","audio/x-ms-wma","flv-application/octet-stream","audio/x-ms-wmv","video/mp4","video/x-flv","audio/x-wav","application/msword","video/mpeg"];//文件类型 private $tmpName; private $fileName; private $error; private $fileSize;//上传文件大小 private $maxSize=10000000;//最大允许上传大小 private $upName; private $upDir="uploadfile/";//上传目录 //构造函数 默认为图片上传 function __construct($upType="image") { $this->tmpName = $_FILES["file"]["tmp_name"]; $this->fileName = $_FILES["file"]["name"]; $this->error = $_FILES["file"]["error"]; $this->fileSize = $_FILES["file"]["size"]; $this->upName=date('Y') . date('m') . date('d') . uniqid();//生成随机文件名 //判断文件大小 if ($this->fileSize > $this->maxSize) exit ("文件超过".($this->maxSize / 1024 / 1024)." M大小"); if ($this->error > 0) exit($error);//判断上传错误 if ($upType== "image") { $this->checkImage(); }else{ $this->checkFile(); } $this->uploadFile(); } //检测图片类型 function checkImage() { $ftype=getimagesize($this->tmpName); if (!in_array($ftype['mime'],$this->imageType)) { exit("非法图片类型"); } } //检测文件类型 function checkFile() { $finfo = finfo_open(FILEINFO_MIME_TYPE); $ftype= finfo_file($finfo, $this->tmpName);//根据文件内容来判断文件类型 finfo_close($finfo); if (!in_array($ftype,$this->fileType)) { exit("非法文件类型"); } } //获得文件扩展名 function getExtension($fileext) { return pathinfo($fileext, PATHINFO_EXTENSION); } //上传文件 function uploadFile() { if (!is_uploaded_file($this->tmpName)) { exit("非法上传"); } else { move_uploaded_file($this->tmpName, //"upload/" . $_FILES["file"]["name"]); $this->upDir . $this->upName .'.'. $this->getExtension($this->fileName)); echo "上传为: " . $this->upDir . $this->upName .'.'. $this->getExtension($this->fileName); } } } $up=new UploadFile();//上传图片 //$up=new UploadFile("file");//上传文件 ?>
2023年08月07日
8 阅读
0 评论
0 点赞
2023-08-07
php curl 突破防盗链
php curl 突破防盗链<?php $img=$_GET['img']; function fetch_urlpage_contents($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_TIMEOUT, 1000); curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 1000); curl_setopt($ch, CURLOPT_USERAGENT, 'Googlebot/2.1 (+http://www.google.com/bot.html)'); curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-FORWARDED-FOR:110.80.7.42', 'CLIENT-IP:110.80.7.42')); //构造IP curl_setopt($ch, CURLOPT_REFERER, "http://www.baidu.com/"); //构造来路 //curl_setopt($ch, CURLOPT_HEADER, 1); $file_contents = curl_exec($ch); $imgurl=str_replace("http://","",$url); $imgurl=str_replace("/","-",$imgurl); $fp = fopen('imgs/'.$imgurl, 'w'); fwrite($fp,$file_contents); fclose($fp); header("Location:imgs/$imgurl"); curl_close($ch); return $file_contents; } $urls='http://img1.xxxxxx.com/'.$img; $haha=fetch_urlpage_contents($urls); //echo $haha;
2023年08月07日
32 阅读
0 评论
0 点赞
2023-08-07
PHP获取网页内容的几种方法
PHP获取网页内容的几种方法方法1: 用file_get_contents 以get方式获取内容<?php$url='http://www.domain.com/?para=123';$html = file_get_contents($url);echo $html;?>方法2:用file_get_contents函数,以post方式获取url<?php$url = 'http://www.domain.com/test.php?id=123';$data = array ('foo' => 'bar');$data = http_build_query($data);$opts = array ('http' => array ('method' => 'POST','header'=> "Content-type: application/x-www-form-urlencoded\r\n" ."Content-Length: " . strlen($data) . "\r\n",'content' => $data));$ctx = stream_context_create($opts);$html = @file_get_contents($url,'',$ctx);如果需要再传递cookie数据,则把'header'=> "Content-type: application/x-www-form-urlencoded\r\n" ."Content-Length: " . strlen($data) . "\r\n",修改为'header'=> "Content-type: application/x-www-form-urlencoded\r\n" ."Content-Length: " . strlen($data) . "\r\n"."cookie:cookie1=c1;cookie2=c2\r\n" ;即可方法3: 用fopen打开url, 以get方式获取内容<?php$fp = fopen($url, 'r');$header = stream_get_meta_data($fp);//获取报头信息while(!feof($fp)) {$result .= fgets($fp, 1024);}echo "url header: {$header} ":echo "url body: $result";fclose($fp);?>方法4: 用fopen打开url, 以post方式获取内容<?php$data = array ('foo2' => 'bar2','foo3'=>'bar3');$data = http_build_query($data);$opts = array ('http' => array ('method' => 'POST','header'=> "Content-type: application/x-www-form-urlencoded\r\nCookie:cook1=c3;cook2=c4\r\n" ."Content-Length: " . strlen($data) . "\r\n",'content' => $data));$context = stream_context_create($opts);$html = fopen('http://www.test.com/zzzz.php?id=i3&id2=i4','rb' ,false, $context);$w=fread($html,1024);echo $w;?>方法5:用fsockopen函数打开url,以get方式获取完整的数据,包括header和body<?phpfunction get_url ($url,$cookie=false){$url = parse_url($url);$query = $url[path]."?".$url[query];echo "Query:".$query;$fp = fsockopen( $url[host], $url[port]?$url[port]:80 , $errno, $errstr, 30);if (!$fp) {return false;} else {$request = "GET $query HTTP/1.1\r\n";$request .= "Host: $url[host]\r\n";$request .= "Connection: Close\r\n";if($cookie) $request.="Cookie: $cookie\n";$request.="\r\n";fwrite($fp,$request);while(!@feof($fp)) {$result .= @fgets($fp, 1024);}fclose($fp);return $result;}}//获取url的html部分,去掉headerfunction GetUrlHTML($url,$cookie=false){$rowdata = get_url($url,$cookie);if($rowdata){$body= stristr($rowdata,"\r\n\r\n");$body=substr($body,4,strlen($body));return $body;}return false;}?>方法6:用fsockopen函数打开url,以POST方式获取完整的数据,包括header和body<?phpfunction HTTP_Post($URL,$data,$cookie, $referrer=""){// parsing the given URL$URL_Info=parse_url($URL);// Building referrerif($referrer=="") // if not given use this script as referrer$referrer="111";// making string from $dataforeach($data as $key=>$value)$values[]="$key=".urlencode($value);$data_string=implode("&",$values);// Find out which port is needed - if not given use standard (=80)if(!isset($URL_Info["port"]))$URL_Info["port"]=80;// building POST-request:$request.="POST ".$URL_Info["path"]." HTTP/1.1\n";$request.="Host: ".$URL_Info["host"]."\n";$request.="Referer: $referer\n";$request.="Content-type: application/x-www-form-urlencoded\n";$request.="Content-length: ".strlen($data_string)."\n";$request.="Connection: close\n";$request.="Cookie: $cookie\n";$request.="\n";$request.=$data_string."\n";$fp = fsockopen($URL_Info["host"],$URL_Info["port"]);fputs($fp, $request);while(!feof($fp)) {$result .= fgets($fp, 1024);}fclose($fp);return $result;}?>方法7:使用curl库,使用curl库之前,可能需要查看一下php.ini是否已经打开了curl扩展<?php$ch = curl_init();$timeout = 5;curl_setopt ($ch, CURLOPT_URL, 'http://www.domain.com/');curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);$file_contents = curl_exec($ch);curl_close($ch);echo $file_contents;?>
2023年08月07日
10 阅读
0 评论
0 点赞
2023-08-07
MySql类
MySql类<?php/***mysql数据库类leninx 2013.5*/class DbMysql{public $link;public $result;function __construct(){}/**连接数据库*/public function connect($dbname,$dbpassword,$dbdatabase,$dbhost='localhost',$dbcharset='UTF8'){if(!$this->link) {$this->link = mysql_connect($dbhost, $dbname, $dbpassword) or die(mysql_error());$dbVersion = mysql_get_server_info($this->link);//设置字符集mysql_set_charset($dbcharset,$this->link) or die("can not set charset");if($dbVersion >'5.0.1'){mysql_query("SET sql_mode=''",$this->link);mysql_query("SET character_set_connection=".$dbcharset.", character_set_results=".$dbcharset.", character_set_client=binary", $this->link);//为了防止采集等需要较长运行时间的程序超时,在运行这类程序时设置系统等待和交互时间// @mysql_query("SET interactive_timeout=3600, wait_timeout=3600 ;",$link);}mysql_select_db($dbdatabase, $this->link) or die("can not select datebase");}return $this->link;}/**执行查询*/public function query($sql){if(!$this->link ) return false;if($this->result) {$this->free();}if($this->result = mysql_query($sql, $this->link)) {return $this->result;//return $this;}else{return false;}}/**执行查询2*/public function queryd($sql){return mysql_query($sql,$this->link);}/*执行写入语句*/public function execute($sql){if(!$this->link ) return false;if($this->result) {$this->free();}$result = mysql_query($sql, $this->link);if($result == false) {trigger_error('MySQL execute error: ' . mysql_error() . ' ['.$sql.']');}}/**取得所有数据*/public function fetchAll($result_type = MYSQL_ASSOC){$data = null;//$query = $this->query($sql);while($row = mysql_fetch_array($this->result, $result_type)){$data[] = $row;}mysql_data_seek($this->result, 0);// 移动内部结果的指针从0行开始。//mysql_free_result($result);return $data;}/*取得一行数据*/public function fetchArray($type=MYSQL_ASSOC){return mysql_fetch_array($this->result,$type);}/**取得一行另一种用法,在递归时用等*/public function fetchRow($result,$type=MYSQL_ASSOC){return mysql_fetch_array($result,$type);}/**对象形式取得一行数据*/public function fetchObject(){return mysql_fetch_object($this->result);}/**返回记录行数*/public function numRows(){return mysql_num_rows($this->result);}/**上一次操作的影响数*/public function affectedRows(){return mysql_affected_rows($this->link);}/*取得最后一次插入记录的ID值@return int 返回最后一次插入记录的ID值*/public function insertId(){return ($id = mysql_insert_id($this->link)) >= 0 ? $id : mysql_result($this->query("SELECT last_insert_id()"), 0);}/**获取错误信息*/public function error(){return (($this->link) ? mysql_error($this->link) : mysql_error());}/**获取错误代码*/public function errno(){return intval(($this->link) ? mysql_errno($this->link) : mysql_errno());}/**释放结果集*/public function free(){mysql_free_result($this->result);}/**转义字符*/public function escape($str){return mysql_real_escape_string($str,$this->link);}/**关闭数据库连接*/public function close(){return @mysql_close($this->link);}/**析构*/function __destruct(){$this->free();$this->close();}}?>
2023年08月07日
10 阅读
0 评论
0 点赞
2023-08-07
超强php验证码升级版
超强php验证码升级版识别难度更大<?php function getCode($length = 32, $mode = 0) { switch ($mode) { case '1' : $str = '123456789'; break; case '2' : $str = 'abcdefghijklmnopqrstuvwxyz'; break; case '3' : $str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; break; case '4' : $str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; break; case '5' : $str = 'ABCDEFGHIJKLMNPQRSTUVWXYZ123456789'; break; case '6' : $str = 'abcdefghijklmnopqrstuvwxyz1234567890'; break; case '7' ://中文验证码 break; default : $str = 'ABCDEFGHIJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789'; break; } $result = ''; for($i = 0; $i < $length; $i ++) { if ($mode == 7) { $str [$i] = chr ( mt_rand ( 176, 215 ) ) . chr ( mt_rand ( 161, 249 ) ); $str [$i] = iconv ( "GB2312", "UTF-8", $str [$i] ); //imagettftext是utf-8的,所以先转换下 $result .= $str [$i]; } else { $l = strlen ( $str ) - 1; $num = mt_rand ( 0, $l ); $result .= $str [$num]; } } return $result; } //建立验证图片 function createAuthNumImg($randStr, $fontName, $imgW = 100, $imgH = 40) { header ( "content-type: image/png" ); $image = imagecreate ( $imgW, $imgH ); $fontSize = mt_rand(17,20);//字号 //$green = imagecolorallocate($image,0x6b,0xc1,0x46); $gray = imagecolorallocate ( $image, 255, 255, 255 ); //灰色 $red = imagecolorallocate ( $image, 255, 102, 204 );//粉色 $blue = imagecolorallocate($image,0x53,0x68,0xbd); $colors = array($red, $gray, $blue); $color_b = imagecolorallocate ( $image, 0, 0, 0 ); //黑色 $color_d = imagecolorallocate ( $image,98,178, 28 ); //绿色 $color_e = imagecolorallocate ( $image,38,98, 223 ); //蓝色 $color_c = imagecolorallocate ( $image,255,0, 0 ); //红色 $color_f = imagecolorallocate ( $image,128,0, 255 ); //紫色 $color_g = imagecolorallocate ( $image,0,128, 128 ); // $color = array($color_b, $color_c, $color_d,$color_e); shuffle($color); $colorrnd=imagecolorallocate ( $image,mt_rand(0,255),mt_rand(0,255), mt_rand(0,255) ); for($i = 0; $i < 1000; $i ++) { //绘背景干扰点 //imagesetpixel ( $image, mt_rand ( 0, $imgW ), mt_rand ( 0, $imgH ), $colors[rand(0,count($colors)-1)]); } imagerectangle ( $image, 0, 0, $imgW - 1, $imgH - 1, $color_b );//绘制边框 $str1=substr($randStr,0,1); $str2=substr($randStr,1,1); $str3=substr($randStr,2,1); $str4=substr($randStr,3,1); $range=mt_rand(-20,20); //imagettftext ( $image, $fontSize, 5, 3, 25, $color_b, $fontName, $randStr);///将验证字符绘入图片 字符旋转 for($i=1;$i<=4;$i++) { $p=$i-1; $str=$randStr["$p"]; //imagettftext ( $image, mt_rand(17,20), mt_rand(-20,20), $i*12, mt_rand(20,25), $color[mt_rand(0,count($color)-1)], $fontName, $str);///将验证字符绘入图片 字符旋转 imagettftext ( $image, mt_rand(17,20), mt_rand(-20,20), $i*12, mt_rand(20,25), $color[$i-1], $fontName, $str);///将验证字符绘入图片 字符旋转 } //imagettftext ( $image, mt_rand(17,20), mt_rand(-20,20), mt_rand(2,5), mt_rand(20,25), $color_b, $fontName, $str1);///将验证字符绘入图片 字符旋转 //imagettftext ( $image, mt_rand(17,20), mt_rand(-20,20), mt_rand(16,18), mt_rand(20,25), $color_c, $fontName, $str2);///将验证字符绘入图片 字符旋转 //imagettftext ( $image, mt_rand(17,20), mt_rand(-20,20), mt_rand(28,30), mt_rand(20,25), $color_d, $fontName, $str3);///将验证字符绘入图片 字符旋转 //imagettftext ( $image, mt_rand(17,20), mt_rand(-20,20), mt_rand(36,38), mt_rand(20,25), $color_e, $fontName, $str4);///将验证字符绘入图片 字符旋转 for($i=0; $i<4; $i++){ //绘背景干扰线 //imageline($image, mt_rand(0,5), mt_rand(6,18), mt_rand(65,$imgW), mt_rand(6,$imgH), $colorrnd);//一条干扰线 $h=30; $h1=rand(-5,5); $h2=rand(-1,1); $w2=rand(10,15); $h3=rand(4,6); $w=75; for($i=-$w/2;$i<$w/2;$i=$i+0.1) { $y=$h/$h3*sin($i/$w2)+$h/2+$h1; imagesetpixel($image,$i+$w/2,$y,$color[$p]); $h2!=0?imagesetpixel($image,$i+$w/2,$y+$h2,$color[$p]):null; } } imagepng ( $image ); imagedestroy ( $image ); } session_start (); $verifyCode = GetCode ( 4 ); $_SESSION ['VERIFY_CODE'] = $verifyCode ; createAuthNumImg ( $verifyCode, "font.ttf", 75, 30); //字体存放路径,如果你没有文件就去C:\WINDOWS\Fonts文件中找一个吧。 /** 问答模式 $a=GetCode(2,1); $b=GetCode(1,1); $passPort = $a."+".$b."=?"; $verifyCode = $a+$b; $_SESSION ['VERIFY_CODE'] = $verifyCode ; createAuthNumImg ( $passPort, "font.ttf", 75, 30); */ ?>
2023年08月07日
9 阅读
0 评论
0 点赞
1
...
25
26
27
28