php 模仿用户登陆读取DZ 论坛验码程序-3
error_reporting(0);
session_start();
header("Content-Type:text/html;charset=utf-8");
require("config.php");
$_SESSION["cookie_jar1"]=tempnam("temp","C2");
$url=DZ."ajax.php?inajax=1&action=checkseccode&seccodeverify=".$_GET["code"];
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_COOKIEFILE,$_SESSION["cookie_jar"]);
curl_setopt($ch,CURLOPT_COOKIEJAR,$_SESSION["cookie_jar1"]);
$html=curl_exec($ch);
preg_match("/(?<=encoding=").*?(?=")/",$html,$charset);
if($charset[0]!=="utf-8")
{
$html=iconv($charset[0],"utf-8",$html);
}
curl_close($ch);
preg_match("/(?<=CDATA[).*?(?=])/",$html,$outs);
echo $outs[0];
?>
if( isset($_FILES['upImg']) )
{
if( $userGroup[$loginArr['group']]['upload'] == 0 )
{
echo '{"error":"您所在的用户组无权上传图片!"}';
}
else
{
$savePath = "attachment/img/".date('Y/m/d/H');mkDirs($savePath);
$fileType = strtolower(strrchr($_FILES['upImg']['name'],"."));
if ( !in_array($fileType, array(".jpg",".jpeg",".gif",".png")) )
{
echo '{"error":"目前仅支持格式为jpg、jpeg、gif、png的图片!"}';
}
elseif( $_FILES['upImg']['size'] > 204800 )
{
echo '{"error":"图片不能超过200K!"}';
}
else
{
$saveImg = $savePath."/".$loginArr['uid']."_".time().rand().$fileType;if( @move_uploaded_file($_FILES['upImg']['tmp_name'], $saveImg) )
{
echo '{"error":"","msg":"http://'.$site_domain.$site_catalog.$saveImg.'"}';
}
else
{
echo '{"error":"图片上传失败!"}';
}
}
}
}if( $loginArr['state'] == 0 )
{
echo '{"error":"您还没有登录!"}';
}
else
{
$avatarPath = "attachment/avatar/".($loginArr['uid']%32)."/".($loginArr['uid']%257)."/".$loginArr['uid'];if( isset($_FILES['upAvatar']) )
{
mkDirs($avatarPath);$fileType = strtolower(strrchr($_FILES['upAvatar']['name'],"."));
if ( !in_array($fileType, array(".jpg",".jpeg",".gif",".png")) )
{
echo '{"error":"目前仅支持格式为jpg、jpeg、gif、png的图片!"}';
}
elseif( $_FILES['upAvatar']['size'] > 2097152 )
{
echo '{"error":"图片不能超过2MB!"}';
}
else
{
$imgInfo = @getimagesize($_FILES['upAvatar']['tmp_name']);if( !$imgInfo || !in_array($imgInfo[2], array(1,2,3)) )
{
echo '{"error":"系统无法识别您上传的文件!"}';
}
else
{
$TmpAvatar = $avatarPath."/temp".$fileType;
if( @move_uploaded_file($_FILES['upAvatar']['tmp_name'], $TmpAvatar) )
{
$maxWidth = 520;$maxHeight = 520;
if( $maxWidth > $imgInfo[0] || $maxHeight > $imgInfo[1] )
{
$maxWidth = $imgInfo[0];$maxHeight = $imgInfo[1];
}
else
{
if ( $imgInfo[0] < $imgInfo[1] )
$maxWidth = ($maxHeight / $imgInfo[1]) * $imgInfo[0];
else
$maxHeight = ($maxWidth / $imgInfo[0]) * $imgInfo[1];
}if( $maxWidth < 40 )
{
$maxWidth = 40;
}if( $maxHeight < 40 )
{
$maxHeight = 40;
}$image_p = imagecreatetruecolor($maxWidth, $maxHeight);
switch($imgInfo[2])
{
case 1:
$image = imagecreatefromgif($TmpAvatar);
break;
case 2:
$image = imagecreatefromjpeg($TmpAvatar);
break;
case 3:
$image = imagecreatefrompng($TmpAvatar);
break;
}imagecopyresampled($image_p, $image, 0, 0, 0, 0, $maxWidth, $maxHeight, $imgInfo[0], $imgInfo[1]);
imagejpeg($image_p, $avatarPath."/temp.jpg",100);
imagedestroy($image_p);
imagedestroy($image);
if( $fileType != ".jpg" && file_exists($TmpAvatar) )
{
unlink($TmpAvatar);
}echo '{"error":"","url":"'.$avatarPath.'/temp.jpg?'.rand().'","width":"'.$maxWidth.'","height":"'.$maxHeight.'"}';
}
else
{
echo '{"error":"图片上传失败!"}';
}
}
}
}if( isset($_POST['x'],$_POST['y'],$_POST['w'],$_POST['h']) )
{
if( is_numeric($_POST['x']) && is_numeric($_POST['y']) && $_POST['w'] > 0 && $_POST['h'] > 0 )
{
$image_p = imagecreatetruecolor(40, 40);$image = imagecreatefromjpeg($avatarPath."/temp.jpg");
imagecopyresampled($image_p, $image, 0, 0, $_POST['x'], $_POST['y'], 40, 40, $_POST['w'], $_POST['h']);
imagejpeg($image_p, $avatarPath."/40_40.jpg",100);
imagedestroy($image_p);
imagedestroy($image);
unlink($avatarPath."/temp.jpg");
echo "1";
}
}if( isset($_POST['avatar']) && $_POST['avatar'] == "delete" )
{
if( file_exists($avatarPath."/temp.jpg") )
{
unlink($avatarPath."/temp.jpg");
}
}
}ob_end_flush();
error_reporting(0);
session_start();
require("config.php");
if(!is_dir("temp"))
{
mkdir("temp",0777);
}
$c=tempnam("temp","c");
$url=DZ."logging.php?action=login";
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_USERAGENT,$_SERVER["HTTP_USER_AGENT"]);
curl_setopt($ch,CURLOPT_COOKIEJAR,$c);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$html=curl_exec($ch);
preg_match("/(?<=charset=).*?(?=")/",$html,$charset);
if($charset[0]!=="utf-8")
{
$html=iconv($charset[0],"utf-8",$html);
}
curl_close($ch);
preg_match("/(?<=formhash" value=").*?(?=")/",$html,$outs);
$_SESSION["hash"]=$outs[0];
$c1=tempnam("temp","c1");
$re_url=DZ."ajax.php?action=updateseccode&secchecktype=&inajax=1&ajaxtarget=seccodeverify_menu";
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$re_url);
curl_setopt($ch,CURLOPT_USERAGENT,$_SERVER["HTTP_USER_AGENT"]);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_COOKIEFILE,$c);
curl_setopt($ch,CURLOPT_COOKIEJAR,$c1);
$html=curl_exec($ch);
curl_close($ch);
preg_match("/(?<=src=").*?(?=")/",$html,$outs);
$_SESSION["cookie_jar"]=tempnam("temp","C1_");
$url=DZ.$outs[0];
$ch=curl_init();
curl_setopt($ch,CURLOPT_REFERER,$re_url);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_USERAGENT,$_SERVER["HTTP_USER_AGENT"]);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_COOKIEFILE,$c1);
curl_setopt($ch,CURLOPT_COOKIEJAR,$_SESSION["cookie_jar"]);
$html=curl_exec($ch);
curl_close($ch);
echo $html;
ExcelFileParser处理excel获得数据 可作批量导入到数据库
提交表单
<!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=utf-8" />
<title>Excel数据获取演示</title>
<meta name="Keywords" content="TODO" />
<meta name="Description" content="TODO"/>
</head>
<body>
<div>
<div>Excel数据获取演示</div>
<div>
<form method="POST" action="/Index/parse" enctype="multipart/form-data">
<input type="file" name="excel" value="" />
<input type="submit" name="submit" value="提交" />
</form>
</div>
</div>
</body>
</html>
提交处理
[php]
<?php
/**
* CopyRight (c) 2009,
* All rights reserved.
* 文件名:
* 摘 要:
*
* @author 星期八 ixqbar@hotmail.com
* @version
*/
class IndexAction extends Action
{
/**
* 构造函数
*/
public function __construct()
{
parent::__construct();
}
/**
* 默认索引页
*/
public function index()
{
$this->display();
}
/**
* 提交处理
*/
public function parse()
{
/**
* $_FILES数组说明
* array(n) {
* ["表单文件框名称"] => array(5) {
* ["name"] => 提交文件名称
* ["type"] => 提交文件类型 Excel为"application/vnd.ms-excel"
* ["tmp_name"] => 临时文件名称
* ["error"] => 错误(0成功1文件太大超过upload_max_filesize2文件太大超过MAX_FILE3上传不完整4没有上传文件)
* ["size"] => 文件大小(单位:KB)
* }
* }
*/
$return=array(0,'');
/**
* 判断是否提交
* is_uploaded_file(文件名称)用于确定指定的文件是否使用POST方法上传,防止非法提交,通常和move_upload_file一起使用保存上传文件到指定的路径
*/
if(!isset($_FILES) || !is_uploaded_file($_FILES['excel']['tmp_name']))
{
$return=array(1,'提交不合法');
}
//处理
if(0 == $return[0])
{
import('@.Util.ExcelParser');
$excel=new ExcelParser($_FILES['excel']['tmp_name']);
$return=$excel->main();
}
//输出处理
print_r($return);
}
}
?>
[/php]
处理类
[php]
<?php
/**
* CopyRight (c) 2009,
* All rights reserved.
* 文件名:excel数据获取
* 摘 要:
*
* @author 星期八 ixqbar@hotmail.com
* @version 0.1
*/
class ExcelParser
{
private $_data=array(0,'');
private $_excel_handle;
private $_excel=array();
/**
* 构造函数
* @param <string> $filename 上传文件临时文件名称
*/
public function __construct($filename)
{
/**
* 引入excelparser类
* 普通方法为
* requires 路径.'excelparser.php';
* import为ThinkPHP自带导入类方法
*/
import('@.Util.PHPExcelParser.excelparser','','.php');
$this->_excel_handle=new ExcelFileParser();
//错误获取
$this->checkErrors($filename);
}
/**
* 错误校验
*/
private function checkErrors($filename)
{
/**
* 方法一
*/
$error_code=$this->_excel_handle->ParseFromFile($filename);
/**
* 方法二
* $file_handle = fopen($this->_filename,'rb');
* $content = fread($file_handle,filesize($this->_filename));
* fclose($file_handle);
* $error_code = $this->_excel->ParseFromString($content);
* unset($content,$file_handle);
*/
switch($error_code)
{
case 0:
//无错误不处理
break;
case 1:
$this->_data=array(1,'文件读取错误(Linux注意读写权限)');
break;
case 2:
$this->_data=array(1,'文件太小');
break;
case 3:
$this->_data=array(1,'读取Excel表头失败');
break;
case 4:
$this->_data=array(1,'文件读取错误');
break;
case 5:
$this->_data=array(1,'文件可能为空');
break;
case 6:
$this->_data=array(1,'文件不完整');
break;
case 7:
$this->_data=array(1,'读取数据错误');
break;
case 8:
$this->_data=array(1,'版本错误');
break;
}
unset($error_code);
}
/**
* Excel信息获取
*/
private function getExcelInfo()
{
if(1==$this->_data[0])return;
/**
* 获得sheet数量
* 获得sheet单元对应的行和列
*/
$this->_excel['sheet_number']=count($this->_excel_handle->worksheet['name']);
for($i=0;$i<$this->_excel['sheet_number'];$i++)
{
/**
* 行于列
* 注意:从0开始计数
*/
$row=$this->_excel_handle->worksheet['data'][$i]['max_row'];
$col=$this->_excel_handle->worksheet['data'][$i]['max_col'];
$this->_excel['row_number'][$i]=($row==NULL)?0:++$row;
$this->_excel['col_number'][$i]=($col==NULL)?0:++$col;
unset($row,$col);
}
}
/**
* 中文处理函数
* @return <string>
*/
private function uc2html($str)
{
$ret = '';
for( $i=0; $i<strlen($str)/2; $i++ )
{
$charcode = ord($str[$i*2])+256*ord($str[$i*2+1]);
$ret .= '&#'.$charcode.';';
}
return mb_convert_encoding($ret,'UTF-8','HTML-ENTITIES');
}
/**
* Excel数据获取
*/
private function getExcelData()
{
if(1==$this->_data[0])return;
//修改标记
$this->_data[0]=1;
//获取数据
for($i=0;$i<$this->_excel['sheet_number'];$i++)
{
/**
* 对行循环
*/
for($j=0;$j<$this->_excel['row_number'][$i];$j++)
{
/**
* 对列循环
*/
for($k=0;$k<$this->_excel['col_number'][$i];$k++)
{
/**
* array(4) {
* ["type"] => 类型 [0字符类型1整数2浮点数3日期]
* ["font"] => 字体
* ["data"] => 数据
* ...
* }
*/
$data=$this->_excel_handle->worksheet['data'][$i]['cell'][$j][$k];
switch($data['type'])
{
case 0:
//字符类型
if($this->_excel_handle->sst['unicode'][$data['data']])
{
//中文处理
$data['data'] = $this->uc2html($this->_excel_handle->sst['data'][$data['data']]);
}
else
{
$data['data'] = $this->_excel_handle->sst['data'][$data['data']];
}
break;
case 1:
//整数
//TODO
break;
case 2:
//浮点数
//TODO
break;
case 3:
//日期
//TODO
break;
}
$this->_data[1][$i][$j][$k]=$data['data'];
unset($data);
}
}
}
}
/**
* 主函数
* @return <array> array(标识符,内容s)
*/
public function main()
{
//Excel信息获取
$this->getExcelInfo();
//Excel数据获取
$this->getExcelData();
return $this->_data;
}
}
?>
PHP生成扭曲有角度支持中文的图片验证码函数
<?php
function make_rand($length="32"){//验证码文字生成函数
$str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
$result="";
for($i=0;$i<$length;$i++){
$num[$i]=rand(0,61);
$result.=$str[$num[$i]];
}
return $result;
}
$checkcode = make_rand(5);
$im_x=160;
$im_y=32;
function make_crand($length="5") {
$string = '';
for($i=0;$i<$length;$i++) {
$string .= chr(rand(0xB0,0xF7)).chr(rand(0xA1,0xFE));
}
return $string;
}
function getAuthImage($text , $im_x = 230 , $im_y = 32) {
$im = imagecreatetruecolor($im_x,$im_y);
$text_c = ImageColorAllocate($im, mt_rand(0,100),mt_rand(0,100),mt_rand(0,100));
$tmpC0=mt_rand(100,255);
$tmpC1=mt_rand(100,255);
$tmpC2=mt_rand(100,255);
$buttum_c = ImageColorAllocate($im,$tmpC0,$tmpC1,$tmpC2);
imagefill($im, 16, 13, $buttum_c);
//echo $text;
$font = 'c:\WINDOWS\Fonts\simsun.ttc';
//echo strlen($text);
$text=iconv("gb2312","UTF-8",$text);
//echo mb_strlen($text,"UTF-8");
for ($i=0;$i<mb_strlen($text);$i++)
{
$tmp =mb_substr($text,$i,1,"UTF-8");
$array = array(-1,0,1);
$p = array_rand($array);
$an = $array[$p]*mt_rand(1,9);//角度
$size = 20;
imagettftext($im,$size,$an,10+$i*$size*2,25,$text_c,$font,$tmp);
}
$distortion_im = imagecreatetruecolor ($im_x, $im_y);
imagefill($distortion_im, 16, 13, $buttum_c);
for ( $i=0; $i<$im_x; $i++) {
for ( $j=0; $j<$im_y; $j++) {
$rgb = imagecolorat($im, $i , $j);
if( (int)($i+20+sin($j/$im_y*2*M_PI)*10) <= imagesx($distortion_im) && (int)($i+20+sin($j/$im_y*2*M_PI)*10) >=0 ) {
imagesetpixel ($distortion_im, (int)($i+10+sin($j/$im_y*2*M_PI-M_PI*0.5)*3) , $j , $rgb);
}
}
}
//加入干扰象素;
$count = 600;//干扰像素的数量
for($i=0; $i<$count; $i++){
$randcolor = ImageColorallocate($distortion_im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
imagesetpixel($distortion_im, mt_rand()%$im_x , mt_rand()%$im_y , $randcolor);
}
$line_c=5;
//imageline
for($i=0; $i < $line_c; $i++) {
$linecolor = imagecolorallocate($distortion_im, 17, 158, 20);
$lefty = mt_rand(1, $im_x-1);
$righty = mt_rand(1, $im_y-1);
imageline($distortion_im, 0, $lefty, imagesx($distortion_im), $righty, $linecolor);
}
Header("Content-type: image/PNG");
//以PNG格式将图像输出到浏览器或文件;
//ImagePNG($im);
ImagePNG($distortion_im);
//销毁一图像,释放与image关联的内存;
ImageDestroy($distortion_im);
ImageDestroy($im);
}
getAuthImage(make_crand(5));
?>
相关文章
- 这篇文章主要介绍了C#开发Windows窗体应用程序的简单操作步骤,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-04-12
- php 获取用户IP与IE信息程序 function onlineip() { global $_SERVER; if(getenv('HTTP_CLIENT_IP')) { $onlineip = getenv('HTTP_CLIENT_IP');...2016-11-25
- 本文通过例子,讲述了C++调用C#的DLL程序的方法,作出了以下总结,下面就让我们一起来学习吧。...2020-06-25
- 这篇文章主要介绍了微信小程序 页面传值详解的相关资料,需要的朋友可以参考下...2017-03-13
- 本文通过两个示例讲解了一下Process类调用外部应用程序的基本用法,并简单讲解了StartInfo属性,有需要的朋友可以参考一下。...2020-06-25
- php简单用户登陆程序代码 这些教程很对初学者来讲是很有用的哦,这款就下面这一点点代码了哦。 <center> <p> </p> <p> </p> <form name="form1...2016-11-25
- 这篇文章主要介绍了微信小程序 二维码生成工具 weapp-qrcode详解,教大家如何在项目中引入weapp-qrcode.js文件,通过实例代码给大家介绍的非常详细,需要的朋友可以参考下...2021-10-23
- 大概有如下步骤 新建项目Bejs 新建文件package.json 新建文件Gruntfile.js 命令行执行grunt任务 一、新建项目Bejs源码放在src下,该目录有两个js文件,selector.js和ajax.js。编译后代码放在dest,这个grunt会...2014-06-07
- 这篇文章主要介绍了uniapp微信小程序:key失效的解决方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-01-20
将c#编写的程序打包成应用程序的实现步骤分享(安装,卸载) 图文
时常会写用c#一些程序,但如何将他们和photoshop一样的大型软件打成一个压缩包,以便于发布....2020-06-25- 一个用Javascript检测用户输入密码强度的效果代码,以下代码主要是从以下四个方面检测用户输入的密码的强度的,有兴趣的朋友可以自己添加或修改成自己想要的形式! 1. 如果输入的密码位数少于5位,那么就判定为弱。 2. 如果...2015-10-23
- 本文实例讲述了PHP常用的小程序代码段。分享给大家供大家参考,具体如下:1.计算两个时间的相差几天$startdate=strtotime("2009-12-09");$enddate=strtotime("2009-12-05");上面的php时间日期函数strtotime已经把字符串...2015-11-24
- 这篇文章主要介绍了微信小程序 网络请求(GET请求)详解的相关资料,需要的朋友可以参考下...2016-11-22
- 这篇文章主要给大家介绍了关于微信小程序如何获取图片宽度与高度的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-03-10
- 这篇文章主要为大家详细介绍了微信小程序自定义tabbar组件,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-03-14
- 当来访者浏览器语言是中文就进入中文版面,国外的用户默认浏览器不是中文的就跳转英文页面。 <?php $lan = substr( $HTTP_ACCEPT_LANGUAGE,0,5); if ($lan == "zh-cn") print("<meta http-equiv='refresh' c...2015-11-08
- 【问题描述】:同一用户在同一时间多次登录如果不能检测出来,是危险的。因为,你无法知道是否有其他用户在登录你的账户。如何禁止同一用户多次登录呢? 【解决方案】 (1) 每次登录,身份认证成功后,重新产生一个session_id。 s...2015-11-24
- 这篇文章主要介绍了微信小程序(应用号)开发新闻客户端实例的相关资料,需要的朋友可以参考下...2016-10-25
- 这篇文章主要为大家详细介绍了微信小程序实现点击导航条切换页面,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2020-11-19
- 这篇文章主要介绍了微信小程序手势操作之单触摸点与多触摸点的相关资料,需要的朋友可以参考下...2017-03-13