① php 短信验证码数据库如何设计
php做短信验证码,需要将手机号,发送的验证码和时间这几个存到数据库,在添加到数据库的时候,要判断里面有没有要存的手机号,有的话,就更新验证码和时间,没有就是添加,在使用验证码判定的时候,取出验证码和时间,判断验证码是否正确,时间是否在自己设置的有效时间段内,整个过程就是这样。
② php中发送短信验证码的步骤和方法是怎么样的
生成随机字符串-》插入到数据库(数据库表应该有发送到短信手机号码,随机字符串,失效时间,添加时间等字段)-》发送随机字符串短信到手机号码上(根据短信接口实现php一般用webservice)-》ajax比较用户填写的验证码与数据库保存的是否一样
③ 注册时接到手机短信验证是怎么实现的
手机注册验证逻辑是这样的:
首先要找短信服务商如:梦网、云信使、互亿无线等等申请短信发送接口。
网站实现流程如下:
第一步:用户注册时输入手机号,网站首先要通过JS或者ajax+php验证这个号码是不是正确的手机号。
第二步:用户点击发送手机验证码,通过ajax把手机号传到php,这时php生成一个随机的验证码保存在session中,然后通过短信接口把这个验证码发送到这个手机号中。
第三步:用户输入手机收到的验证码注册。网站用session中的验证码和用户输入的验证码比较。
④ php怎么编写手机短信验证码功能
以前在远标做过你的应用应该是这样吧,用户输入手机号码,点击发送短信,用户收到验证码,输入对应的验证码 判断是否正确。
需要:
申请一个短信接口,就是点击发送验证码的时候,提交到接口给该号码下发验证码。
技术方面的实现:
1、点击获取验证码
2、程序ajax post提交到短信接口
3、短信接口服务商 接口判断用户和口令,正确后,下发短信给该号码。
4、用户输入号码,程序判断验证码是否一致。
⑤ 用PHP写一个接口,随机生成6位数字,然后以短信的形式发送到对应的手机号上。从来没写过接口不知道如何写
短信接口需要你有对应的短信服务商才行,通常是第三方短信服务商,这种服务往往是收费的,收取的费用越多,每天可以发送的短信数量越多。
你需要向他们申请短信接口,申请成功后会有接口文档,按照文档中的规定发送相应的数据即可,通常发送的数据包含:需要发送短信的手机号、短信内容。
接口写法通常会在文档中有写,甚至有的文档会附带范例以供开发者参考。
⑥ 怎样用PHP制作验证码
<?php
//验证码类
classValidateCode{
private$charset='';//随机因子
private$code;//验证码
private$codelen=4;//验证码长度
private$width=90;//宽度
private$height=40;//高度
private$img;//图形资源句柄
private$font;//指定的字体
private$fontsize=20;//指定字体大小
private$fontcolor;//指定字体颜色
//构造方法初始化
publicfunction__construct(){
$this->font=dirname(__FILE__).'/font/elephant.ttf';//注意字体路径要写对,否则显示不了图片
}
//生成随机码
privatefunctioncreateCode(){
$_len=strlen($this->charset)-1;
for($i=0;$i<$this->codelen;$i++){
$this->code.=$this->charset[mt_rand(0,$_len)];
}
}
//生成背景
privatefunctioncreateBg(){
$this->img=imagecreatetruecolor($this->width,$this->height);
$color=imagecolorallocate($this->img,mt_rand(157,255),mt_rand(157,255),mt_rand(157,255));
imagefilledrectangle($this->img,0,$this->height,$this->width,0,$color);
}
//生成文字
privatefunctioncreateFont(){
$_x=$this->width/$this->codelen;
for($i=0;$i<$this->codelen;$i++){
$this->fontcolor=imagecolorallocate($this->img,mt_rand(0,156),mt_rand(0,156),mt_rand(0,156));
imagettftext($this->img,$this->fontsize,mt_rand(-30,30),$_x*$i+mt_rand(1,5),$this->height/1.4,$this->fontcolor,$this->font,$this->code[$i]);
}
}
//生成线条、雪花
privatefunctioncreateLine(){
//线条
for($i=0;$i<6;$i++){
$color=imagecolorallocate($this->img,mt_rand(0,156),mt_rand(0,156),mt_rand(0,156));
imageline($this->img,mt_rand(0,$this->width),mt_rand(0,$this->height),mt_rand(0,$this->width),mt_rand(0,$this->height),$color);
}
//雪花
for($i=0;$i<100;$i++){
$color=imagecolorallocate($this->img,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255));
imagestring($this->img,mt_rand(1,5),mt_rand(0,$this->width),mt_rand(0,$this->height),'*',$color);
}
}
//输出
privatefunctionoutPut(){
header('Content-type:image/png');
imagepng($this->img);
imagedestroy($this->img);
}
//对外生成
publicfunctiondoimg(){
$this->createBg();
$this->createCode();
$this->createLine();
$this->createFont();
$this->outPut();
}
//获取验证码
publicfunctiongetCode(){
returnstrtolower($this->code);
}
}
⑦ 求助,哪位大神给说一下,php短信验证码表结构设计
id 自增
mobile 手机号
code 验证码
add_time 生成时间
status 使用状态:1为已使用,0为未使用,默认为0
以上为最简单的结构,需求不复杂应该就够用的了,add_time可以用于判断是否过期,status可以用于判断是否已经使用,要是重新发送验证码的话,就把前面的记录删除掉。如果多个功能用到验证码的话,弄个type字段来区分功能
⑧ 怎么用原生php做验证码
<?php
class validateCode{
private $charset=''; //随机因子
private $_len;
private $code; //验证码
private $codelen=4; //验证码长度
private $width=130; //画布宽度
private $height=50; //画布长度
private $img; //图形资源句柄
private $font; //制定字体
private $fontsize=26;//字体大小
private $fontcolor; //字体颜色
//初始化构造函数
public function __construct(){
$this->font=dirname(__file__).'/validateFont.ttf';
//字体文件及路径,__file__表示当前PHP文件绝对路径,dirname表示这个PHP文件的绝对路径的上一层
}
//生成随机码
private function createCode(){
$this->_len=strlen($this->charset)-1; //strlen表示计算字符串长度
for($i=1;$i<=$this->codelen;$i++){
$this->code.=$this->charset[mt_rand(0,$this->_len)];
}
}
//生成背景
private function createBG(){
$this->img=imagecreatetruecolor($this->width,$this->height);//创建图像
$color=imagecolorallocate($this->img,mt_rand(157,255),mt_rand(157,255),mt_rand(157,255)); //分配颜色函数(红,绿,蓝)
imagefilledrectangle($this->img,0,$this->height,$this->width,0,$color); //矩形区域着色函数(要填充的图像,x1,y1,x2,y2,要填充的颜色),x1,y1,x2,y2表示矩形的对角线
}
//生成文字
private function createFont(){
$_x=$this->width/$this->codelen;
for($i=0;$i<$this->codelen;$i++){
$this->fontcolor=imagecolorallocate($this->img,mt_rand(0,156),mt_rand(0,156),mt_rand(0,156));
imagettftext($this->img,$this->fontsize,mt_rand(-30,30),$_x*$i+mt_rand(1,5),$this->height/1.4,$this->fontcolor,$this->font,$this->code[$i]); //参数 size 为字形的尺寸;angle 为字型的角度,顺时针计算,0 度为水平,也就是三点钟的方向 (由左到右),90 度则为由下到上的文字;x,y 二参数为文字的坐标值 (原点为左上角);参数 col 为字的颜色;fontfile 为字型文件名称,亦可是远端的文件;text 当然就是字符串内容了。
}
}
//生成线条雪花
private function createLine(){
//线条
for($i=0;$i<6;$i++){
$color=imagecolorallocate($this->img,mt_rand(0,156),mt_rand(0,156),mt_rand(0,156));
imageline($this->img,mt_rand(0,$this->width),mt_rand(0,$this->height),mt_rand(0,$this->width),mt_rand(0,$this->height),$color);
}
//雪花
for($i=0;$i<40;$i++){
$color=imagecolorallocate($this->img,mt_rand(200,255),mt_rand(200,255),mt_rand(200,255));
imagestring($this->img,mt_rand(1,5),mt_rand(0,$this->width),mt_rand(0,$this->height),'*',$color);
}
}
//输出
private function outPut(){
header("content-type:image/png");
imagepng($this->img);
imagedestroy($this->img);
}
//对外生成
public function doimg(){
$this->createCode();
$this->createBg();
$this->createFont();
$this->createLine();
$this->outPut();
}
//获取验证码
public function getCode(){
return strtolower($this->code);
}
}
?>
字体自己去找,修改下路径就行了
⑨ php获取手机号与验证码往手机上发短信。
你流程搞错了。应该是这样子:
PHP生成验证码,存进SESSION。将验证码POST到移动API,用户收到后,输入验证码,和SESSION比对。
⑩ 如何实现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();
}