A. thinkphp手机短信验证码怎么处理
1、解压附件到 ThinkPHPLibraryOrg 文件中
新建方法
publicfunctionsend(){
//初始化必填
$options['accountsid']='******';//填写自己的
$options['token']='*****';//填写自己的
//初始化$options必填
$ucpass=newOrgComUcpaas($options);
//随机生成6位验证码
srand((double)microtime()*1000000);//createarandomnumberfeed.
$ychar="0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
$list=explode(",",$ychar);
for($i=0;$i<6;$i++){
$randnum=rand(0,35);//10+26;
$authnum.=$list[$randnum];
}
//短信验证码(模板短信),默认以65个汉字(同65个英文)为一条(可容纳字数受您应用名称占用字符影响),超过长度短信平台将会自动分割为多条发送。分割后的多条短信将按照具体占用条数计费。
$appId="****";//填写自己的
$to=$_POST['to'];
$templateId="1";
$param=$authnum;
$arr=$ucpass->templateSMS($appId,$to,$templateId,$param);
if(substr($arr,21,6)==000000){
//如果成功就,这里只是测试样式,可根据自己的需求进行调节
echo"短信验证码已发送成功,请注意查收短信";
}else{
//如果不成功
echo"短信验证码发送失败,请联系客服";
}
}
前台页面
<formid="form">
<inputtype="text"name="to"id="to"/>
<buttonid="submit">获取验证码</button>
</form>
<scripttype="text/javascript">
$(function(){
$("#submit").click(function(){
vartourl=$("#form").attr("action");
$.post("__URL__/send",{to:$("#to").val()},function(data,textStatus){
alert(data);
});
})
})
</script>
测试时只能给注册手机号和添加白名单手机号码发送
B. php怎么实现验证码的
验证码功能机制实现思路
常规的验证码实现:
a、产生一张png的图片
b、为图片设置背景色
c、设置字体颜色和样式
d、产生4位数的随机的验证码
e、把产生的每个字符调整旋转角度和位置画到png图片上
f、加入噪点和干扰线防止注册机器分析原图片来恶意注册
g、输出图片
h、释放图片所占内存
i、将验证码保存到session或是数据库
j、将和输入的验证码进行对比
短信(邮箱)验证码机制:
a、产生4-6位数的随机的验证码
b、把产生的每个字符保存到session或是数据库
c、将验证码发送到用户的手机(邮箱)
d、用户在规定时间内进行输入
e、将验证码从session或是数据库中取出
f、将和输入的验证码进行对比验证
C. 如何用PHP生成验证码
打开php gd库(你看下phpinfo是否打开,或者直接运行imagecreate,生成验证码)
然后利用session记录验证码(页面传递)
D. 请问PHP生成验证码的类怎么写
<?php
classCode{
//1.定义各个成员有宽、高、画布、字数、类型、画类型
private$width;//宽度
private$height;//高度
private$num;//验证码字数
private$imgType;//生成图片类型
private$Type;//字串类型1,2,3三个选项1纯数字2纯小写字母3大小写数字混合
private$hb;//画布
public$codestr;//验证码字串
publicfunction__construct($height=20,$num=4,$imgType="jpeg",$Type=1){
$this->width=$num*20;
$this->height=$height;
$this->num=$num;
$this->imgType=$imgType;
$this->Type=$Type;
$this->codestr=$this->codestr();
$this->zuhe();
}
//2.定义随机获取字符串函数
privatefunctioncodestr(){
switch($this->Type){
case1://类型为1获取1-9随机数
$str=implode("",array_rand(range(0,9),$this->num));
break;
case2://类型为2获取a-z随机小写字母
$str=implode("",array_rand(array_flip(range(a,z)),$this->num));
break;
case3://类型为3获取数字,小写字母,大写字母混合
for($i=0;$i<$this->num;$i++){
$m=rand(0,2);
switch($m){
case0:
$o=rand(48,57);
break;
case1:
$o=rand(65,90);
break;
case2:
$o=rand(97,122);
break;
}
$str.=sprintf("%c",$o);
}
break;
}
return$str;
}
//3.初始化画布图像资源
privatefunctionHb(){
$this->hb=imagecreatetruecolor($this->width,$this->height);
}
//4.生成背景颜色
privatefunctionBg(){
returnimagecolorallocate($this->hb,rand(130,250),rand(130,250),rand(130,250));
}
//5.生成字体颜色
privatefunctionFont(){
returnimagecolorallocate($this->hb,rand(0,100),rand(0,100),rand(0,100));
}
//6.填充背景颜色
privatefunctionBgColor(){
imagefilledrectangle($this->hb,0,0,$this->width,$this->height,$this->Bg());
}
//7.干扰点
privatefunctionganrao(){
$sum=floor(($this->width)*($this->height)/3);
for($i=0;$i<$sum;$i++){
imagesetpixel($this->hb,rand(0,$this->width),rand(0,$this->height),$this->Bg());
}
}
//8.随机直线弧线
privatefunctionhuxian(){
for($i=0;$i<$this->num;$i++){
imageArc($this->hb,rand(0,$this->width),rand(0,$this->height),rand(0,$this->width),rand(0,$this->height),rand(0,360),rand(0,360),$this->Bg());
}
}
//9.写字
privatefunctionxiezi(){
for($i=0;$i<$this->num;$i++){
$x=ceil($this->width/$this->num)*$i;
$y=rand(1,$this->height-15);
imagechar($this->hb,5,$x+4,$y,$this->codestr[$i],$this->Font());
}
}
//10.输出
privatefunctionOutImg(){
$shuchu="image".$this->imgType;
$header="Content-type:image/".$this->imgType;
if(function_exists($shuchu)){
header($header);
$shuchu($this->hb);
}else{
exit("GD库没有此类图像");
}
}
//11.拼装
privatefunctionzuhe(){
$this->Hb();
$this->BgColor();
$this->ganrao();
$this->huxian();
$this->xiezi();
$this->OutImg();
}
publicfunctiongetCodeStr(){
return$this->codestr;
}
}
$a=newCode();
$a->getCodeStr();
?>
E. 怎么用php实现手机注册和手机验证
在网络找个短信服务提供商,大概0.5分一条,这种稳定些。30秒以内收到。验证就和验证码一样处理了。
F. php实现手机验证码验证注册功能的逻辑是怎样的
手机注册验证逻辑是这样的:
首先要找短信服务商如:梦网、云信使、互亿无线等等申请短信发送接口。
网站实现流程如下:
第一步:用户注册时输入手机号,网站首先要通过JS或者ajax+php验证这个号码是不是正确的手机号。
第二步:用户点击发送手机验证码,通过ajax把手机号传到php,这时php生成一个随机的验证码保存在session中,然后通过短信接口把这个验证码发送到这个手机号中。
第三步:用户输入手机收到的验证码注册。网站用session中的验证码和用户输入的验证码比较。
G. php验证码怎么实现
1.新建code.php验证码生成文件
在此之前必须打开php的GD库,修改php.ini文件的配置,取消extension=php_gd2.dll前面的分号。代码如下:
<?php
session_start();
//生成验证码图片
Header("Content-type: image/PNG");
$im = imagecreate(44,18);
$back = ImageColorAllocate($im, 245,245,245);
imagefill($im,0,0,$back); //背景
srand((double)microtime()*1000000);
//生成4位数字
for($i=0;$i<4;$i++){
$font = ImageColorAllocate($im, rand(100,255),rand(0,100),rand(100,255));
$authnum=rand(1,9);
$vcodes.=$authnum;
imagestring($im, 5, 2+$i*10, 1, $authnum, $font);
}
for($i=0;$i<100;$i++) //加入干扰象素
{
$randcolor = ImageColorallocate($im,rand(0,255),rand(0,255),rand(0,255));
imagesetpixel($im, rand()p , rand()0 , $randcolor);
}
ImagePNG($im);
ImageDestroy($im);
$_SESSION['Checknum'] = $vcodes;
?>
2. 显示验证码图片
在需要显示验证码的页面中加入
<input type="text" name="passcode" >
<img src="code.php">
3.判断并获取验证码的值
验证码是通过第一步骤代码中的$_SESSION['Checknum'] = $vcodes;赋的值,所以验证码的值存在$_SESSION['Checknum']当中。在验证页面,使用以下代码,
...
session_start();//启动会话
$code=$_POST["passcode"];
if( $code == $_SESSION["Checknum"])
{...}即可完成验证码登录。
运行截图:
望采纳,谢谢
H. 怎么用PHP写个验证码
首先,当用户打开页面时随机产生一个session,然后根据这个值生成验证码图片。
第二,将验证码图片显示到表单上。
第三,当用户提交时表单时,比较session里的值与表单中验证码的值进行比较。
简单的实现过程:http://www.nowamagic.net/php/php_CheckCode.php
复杂的验证码图片生成:http://www.admin5.com/article/20080314/75984.shtml
I. php怎么编写手机短信验证码功能
以前在远标做过你的应用应该是这样吧,用户输入手机号码,点击发送短信,用户收到验证码,输入对应的验证码 判断是否正确。
需要:
申请一个短信接口,就是点击发送验证码的时候,提交到接口给该号码下发验证码。
技术方面的实现:
1、点击获取验证码
2、程序ajax post提交到短信接口
3、短信接口服务商 接口判断用户和口令,正确后,下发短信给该号码。
4、用户输入号码,程序判断验证码是否一致。
J. 如何实现php手机短信验证功能
现在网站在建设网站时为了保证用户信息的真实性,往往会选择发短信给用户手机发验证码信息,只有通过验证的用户才可以注册,这样保证了用户的联系信息资料的100%的准确性。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" >
<html xmlns>
<head>
<title></title>
<script src="js/jquery-1.4a2.min.js" type="text/javascript"></script>
<script type="text/javascript">
/*-------------------------------------------*/
var InterValObj; //timer变量,控制时间
var count = 60; //间隔函数,1秒执行
var curCount;//当前剩余秒数
var code = ""; //验证码
var codeLength = 6;//验证码长度
function sendMessage() {
curCount = count;
var dealType; //验证方式
tel = $(’#tel’).val();
if(tel!=’’){
//验证手机有效性
var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+d{8})$/;
if(!myreg.test($(’#tel’).val()))
{
alert(’请输入有效的手机号码!’);
return false;
}
tel = $(’#tel’).val();
//产生验证码
for (var i = 0; i < codeLength; i++) {
code += parseInt(Math.random() * 9).toString();
}
//设置button效果,开始计时
$("#btnSendCode").attr("disabled", "true");
$("#btnSendCode").val("请在" + curCount + "秒内输入验证码");
InterValObj = window.setInterval(SetRemainTime, 1000); //启动计时器,1秒执行一次
//向后台发送处理数据
$.ajax({
type: "POST", //用POST方式传输
dataType: "text", //数据格式:JSON
url: ’yanzhengma.php’, //目标地址(根据实际地址)
data: "&tel=" + tel + "&code=" + code,
error: function (XMLHttpRequest, textStatus, errorThrown) { },
success: function (msg){ }
});
}else{
alert(’请填写手机号码’);
}
}
//timer处理函数
function SetRemainTime() {
if (curCount == 0) {
window.clearInterval(InterValObj);//停止计时器
$("#btnSendCode").removeAttr("disabled");//启用按钮
$("#btnSendCode").val("重新发送验证码");
code = ""; //清除验证码。如果不清除,过时间后,输入收到的验证码依然有效
}
else {
curCount--;
$("#btnSendCode").val("请在" + curCount + "秒内输入验证码");
}
}
</script>
</head>
<body>
<input name="tel" id=tel type="text" />
<input id="btnSendCode" type="button" value="发送验证码" onclick="sendMessage()" /></p>
</body>
</html>
第三、调用短信服务器短信接口
整理的页面是yanzhengma.php(具体根据服务商提供信息)
<?php //提交短信
$post_data = array();
$post_data[’userid’] =短信服务商提供ID;
$post_data[’account’] = ’短信服务商提供用户名’;
$post_data[’password’] = ’短信服务商提供密码’;
// Session保存路径
$sessSavePath = dirname(__FILE__)."/../data/sessions/";
if(is_writeable($sessSavePath) && is_readable($sessSavePath)){
session_save_path($sessSavePath);
}
session_register(’mobliecode’);
$_SESSION[’mobilecode’] = $_POST["code"];
$content=’短信验证码:’.$_POST["code"].’【短信验证】’;
$post_data[’content’] = mb_convert_encoding($content,’utf-8’, ’gb2312’); //短信内容需要用urlencode编码下
$post_data[’mobile’] = $_POST["tel"];
$post_data[’sendtime’] = ’’; //不定时发送,值为0,定时发送,输入格式YYYYMMDDHHmmss的日期值
$url=’http://IP:8888/sms.aspx?action=send’;
$o=’’;
foreach ($post_data as $k=>$v)
{
$o.="$k=".$v.’&’;
}
$post_data=substr($o,0,-1);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //如果需要将结果直接返回到变量里,那加上这句。
$result = curl_exec($ch);
?>
第四:提交表单信息时对短信验证码验证
//手机验证码开始
session_start();
$svalitel = $_SESSION[’mobilecode’];
$vdcodetel = empty($vdcodetel) ? ’’ : strtolower(trim($vdcodetel));
if(strtolower($vdcodetel)!=$svalitel || $svalitel==’’)
{
ResetVdValue();
//echo "Pageviews=".$vdcodetel;
ShowMsg("手机验证码错误!", ’-1’);
exit();
}