蟋蟀
版主
  
村里巡逻队长
UID 67242
精华
0
积分 2035
帖子 1762
金钱 2035 喜悦币
威望 0
人脉 0
阅读权限 100
注册 2005-12-17 来自 福建
状态 离线
|
[广告]: 代充Paypal帐号美元
帮咱也看看,写的错在哪里的,就是不能入库.
<?php
//------------------------------------------------------------------------------------
//
// filename : smsLoginProcess.class.php
//
// author : 蟋蟀
//
// date : 2006-7-28
//
// describ : 输入手机号码,返回验证,然后在新的表单里输入验证码检验
//
//-----------------------------------------------------------------------------------
class smsLoginProcess
{
/** 变量
* $h_db 数据库类mysql句柄
* $filename 存取randCode的文件i
* $mobile 传递的变量手机号码
* $table 数据表
*/
var $h_db=null;
var $filename="";
var $table=array();
var $mobile;
var $randKey;
/** 构造函数 smsLoginProcess
* 参数 无
* 描述 变量初始化
*/
function smsLoginProcess()
{
$this->table['user']="user"; #user数据表
$this->h_db=new mysql(MYSQL_HOST,MYSQL_USER,MYSQL_PW,MYSQL_DB_MBL);
}
/** 函数 setFile
* 参数 string $filename
* 返回 无
* 描述 设置$filename值
*/
function setFile($filename="")
{
if(!isset($filename) || empty($filename))
{
$this->show_Error("文件不存在");
}
$this->filename=$filename;
}
/** 函数 getfile
* 参数 无
* 返回 文件地址名称
* 描述 获取文件
*/
function getFile()
{
return $this->filename;
}
/** 函数 saveCode 保存验证码
* 参数 $type
* 1、存储在数据库中
* 2、存储在文件中
* 返回 提示消息
*/
function saveCode($type=1)
{
$type=(isset($type) && !empty($type))?(int)$type:1;
switch($type)
{
case 1: #数据库方式
$sql="insert into ".$this->table['user']." values('".$this->mobile."','".$this->randKey."')";
$result=$this->h_db->query($sql);
/*echo $this->h_db;*/
$this->h_db->free();
break;
case 2:
$fp=fopen($this->filename,"w");
flock($fp,LOCK_EX);
fputs($fp,serialize(urlencode($this->randKey)));
flock($fp,LOCK_UN);
fclose($fp);
break;
}
}
/** 函数 readCode
* 参数 $type
* 返回 验证码信息或者数组
* 描述 根据$type返回相应的信息
*/
function readCode($type=1)
{
$type=(isset($type) && !empty($type))?(int)$type:1;
if(!is_file($this->filename))
{
$this->show_Error("不是文件类型?);
}
if(!file_exists($this->filename))
{
$this->show_Error("文件不存在");
}
switch($type)
{
case 1:
$sql="select * from $this->table['user'] where `mobileNumber`='".$this->mobile."'";
$record=$h_db->getResult($sql,true);
break;
case 2:
$record=unserialize(urldecode(file_get_contents($this->filename)));
break;
}
return $record;
}
/** 函数 makeRand()
* 参数 $sytle
* 1、生成数字验证码
* 2、生成字母验证码
* 3、生成混合验证码
* 描述 生成验证码
*/
function makeRand($style=3)
{
$sytle=(isset($style) && !empty($style))?intval($style):(int)3;
switch($style)
{
case 1:
$randKey=rand(1000000000,9999999999);
break;
case 2:
$randKey=substr(str_shuffle("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"),0,10);
break;
case 3:
$randKey=substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"),0,10);
break;
}
$this->randKey=$randKey;
}
/** 函数 mobileFilter
* 参数 string $moblie 手机号码
* 返回 成功 ture 失败 false
* 描述 过滤手机号码
*/
function mobileFilter($mobile="")
{
if(!isset($mobile) || empty($mobile))
{
$this->show_Error("没有要验证的手机号码");
}
$this->mobile=$mobile;
if(eregi("13[0-9]{9}",$mobile))
return 1;
else
return 0;
}
/** 函数 show_Error
* 参数 sting $msg
* 返回 无
* 描述 输出错误信息
*/
function show_Error($msg)
{
$msg=(isset($msg) && !empty($msg))?$msg:"错误";
echo $msg;
exit;
}
}
|  吉林php群
27089230 |
|