php代码

<?php
require dirname(__FILE__).'/include/common.inc.php';//这是在cms2008下面做的测试
header("content-type:text/html; charset=utf-8;");
    session_start();//开启缓存
    if (isset($_SESSION['time']))//判断缓存时间
    {
        session_id();
        $_SESSION['time'];
    }
    else
    {
        $_SESSION['time'] = date("Y-m-d H:i:s");
    }
    $_SESSION['mcode']=$_GET['mcode'];//将content的值保存在session中
////如果得到手机号
if($mobile) {
//  echo "2";//得到手机号
//  echo $_SESSION['mcode'];//测试得到的验证码
//  echo '<br/>';
    if((strtotime($_SESSION['time'])+60)<time()) {//将获取的缓存时间转换成时间戳加上60秒后与当前时间比较,小于当前时间即为过期
        session_destroy();
        unset($_SESSION);
        header('content-type:text/html; charset=utf-8;');
        echo '<script>alert("验证码已过期,请重新获取!");</script>';
    }
    else{
    $mcode=$_SESSION['mcode'];
    $post_data = array();
    $post_data['username'] = "test";//用户名
    $post_data['password'] = "test";//密码
    $post_data['mobile'] = $mobile;//手机号,多个号码以分号分隔,如:13407100000;13407100001;13407100002
    $post_data['content'] = urlencode("您本次的验证码是:".$mcode);//内容,如为中文一定要使用一下urlencode函数
    $post_data['extcode'] = "";//扩展号,可选
    $post_data['senddate'] = "";//发送时间,格式:yyyy-MM-dd HH:mm:ss,可选
    $post_data['batchID'] = "";//批次号,可选
    $url='http://116.213.72.20/SMSHttpService/send.aspx';
    $o="";
    foreach ($post_data as $k=>$v)
    {
        $o.= "$k=".$v."&";
    }
    $post_data=substr($o,0,-1);
    $this_header = array("content-type: application/x-www-form-urlencoded;charset=UTF-8");
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER,$this_header);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($ch);//返回相应的标识,具体请参考我方提供的短信API文档
    curl_close($ch);
//  echo $result;
    }
}
?>

html代码

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
  <script src="images/js/jquery.min.js"></script>
  <script src="images/js/check.js"></script>
  <script>
  $(document).ready(function(){
    $("#Submit").click(function get_mobile(){
        var mcode=Math.round(Math.random()*10000);
        $.get("index.php?mobile="+$("#mobile").val()+"&mcode="+mcode,function(data){
//          alert(data);
       
        });
       
        $("#yanzheng").click(function get_code(){
        $.get("index.php?code="+$("#code").val(),function(data){
//          alert(mcode);
            if (mcode==$("#code").val())
            {
                alert('验证码正确,请继续!');
            }
            else{
                alert('验证码错误');
            }
        });
    });
    });
       
var test = {
       node:null,
       count:60,
       start:function(){
          //console.log(this.count);
          if(this.count > 0){
             this.node.innerHTML = this.count--;
             var _this = this;
             setTimeout(function(){
                _this.start();
             },1000);
          }else{
             this.node.removeAttribute("disabled");
             this.node.innerHTML = "再次发送";
             this.count = 60;
          }
       },
       //初始化
       init:function(node){
          this.node = node;
          this.node.setAttribute("disabled",true);
          this.start();
       }
    };
    var btn = document.getElementById("Submit");
    btn.onclick = function(){
       alert("验证信息会发送到"+$("#mobile").val());
       test.init(btn);
    };
  });
 </script>
 </HEAD>
 <BODY>
  <p>手机号:<input type="text" name="mobile" value="" id="mobile" onblur="check_mobile(this.value)"/><span id="mobile_notice"></span></p>
  <p>验证码:<input type="text" name="code" value="" id="code"/><button id="Submit">获取验证码</button></p>
<input type="submit" name="yanzheng" value="下一步" id="yanzheng" />
 </BODY>
check.js
//检测电话号码是否正确
function check_mobile(tel){
	var tel=mobile.replace(/^\s*|\s*$/g,'');
	var length=tel.length;
	if (length==0)
	{
		alert('手机号码不能为空...');
		$('#Submit').attr('disabled','disabled');
		return;
	}
	$a=preg_match('/^((1[3|4|5|8])[0-9]{9})$/',tel);
	if ($a)
	{
		$('#Submit').attr('disabled','');
		return;
	}
	else{
		alert('手机号码格式不正确请重新输入...');
		$('#Submit').attr('disabled','dosabled');
		return;
	}

}


//检测密码
function check_password(password){
	var password=password.replace(/^\s*|\s*$/g,'');
	var length=password.length;
	if (length==0)
	{
		alert('密码不能为空...')
		$('#Submit').attr('disabled','disabled');
		return;
	}
}

//检测确认密码
function check_conform_password(p2){
	var p1=$('#password').val();
	var p2=$('#conform_password').val();
	if (p2!=p1)
	{
		alert('两次输入密码不一致...');
		$('#Submit').attr('disabled','disabled');
		return;
	}
	else{
		$('#Submit').attr('disabled','');
		return;
	}
}


//选中复选框
//function check_box(){
//	
//}
////检查用户名
//function check_username(username){
//	alert(username);
//	exit;
//	var username=username.replace(/^\s*|\s*$/g,'');
//	var length=username.length;
//	if (length==0)//用户名为空的时候
//	{
//		$('#username_notice').html('用户名不能为空');
//		$('#Submit').attr('disabled','disabled');
//		return;
//	}
//	else if (length<2)
//	{
//		$('#username_notice').html('用户名位大于2位的');
//		$('#Submit').attr('disabled','disabled');
//		return;
//	}
//	else if (length>4)
//	{
//		$('#username_notice').html('用户名不能大于!');
//		$('#Submit').attr('disabled','disabled');
//		return;
//	}
//	else{
//		$('#username_notice').html('请继续填写');
//		$('#Submit').attr('disabled','');
//		return;
//	}
//		//正则匹配中文名字/[\x{4e00}-\x{9fa5}]+/u
//		$a=preg_match('/^[a-zA-Z][a-zA-Z0-9]\w{2,19}$/',username);
//		if($a) {
//			$('#username_notice').html('姓名正确请继续');
//			$('#Submit').attr('disabled','');
//			return;
//		}
//		else{
//			$('#username_notice').html('姓名格式不正确');
//			$('#Submit').attr('disabled','dosabled');
//			return;
//		}
//
//
//}
//
////检测公司名称
//function check_company(company){
////	alert(company);
////	exit;
//	var company=company.replace(/^\s*|\s*$/g,'');
//	var clength=company.length;
////	alert(clength);
//	if (clength==0)
//	{
//		$('#company_notice').html('公司名称不能为空');
//		$('#Submit').attr('disabled','disabled');
//		return;
//	}
//	if (clength<7)
//	{
//		$('#company_notice').html('公司名称不能小于7个汉字');
//		$('#Submit').attr('disabled','disabled');
//		return;
//	}
//	if (clength>20)
//	{
//		$('#company_notice').html('公司名称不能超过20个汉字');
//		$('#Submit').attr('disabled','disabled');
//		return;
//	}
//
//	$a=preg_match('/^[a-zA-Z][a-zA-Z0-9]\w{7,20}$/',company);
//		if($a) {
//			$('#company_notice').html('公司名称正确请继续');
//			$('#Submit').attr('disabled','');
//			return;
//		}
//		else{
//			$('#company_notice').html('公司名称格式不正确');
//			$('#Submit').attr('disabled','dosabled');
//			return;
//		}
//}
//
////检测城市
//function check_city(city){
////	alert(company);
////	exit;
//	var city=city.replace(/^\s*|\s*$/g,'');
//	var length=city.length;
////	alert(clength);
//	if (length==0)
//	{
//		$('#city_notice').html('城市名称不能为空');
//		$('#Submit').attr('disabled','disabled');
//		return;
//	}
//	if (clength<1)
//	{
//		$('#city_notice').html('城市名称不能小于1个汉字');
//		$('#Submit').attr('disabled','disabled');
//		return;
//	}
//	if (clength>4)
//	{
//		$('#city_notice').html('公司名称不能超过4个汉字');
//		$('#Submit').attr('disabled','disabled');
//		return;
//	}
//
//	$a=preg_match('/^[a-zA-Z][a-zA-Z0-9]\w{2,4}$/',company);
//		if($a) {
//			$('#city_notice').html('城市名称正确请继续');
//			$('#Submit').attr('disabled','');
//			return;
//		}
//		else{
//			$('#city_notice').html('城市名称格式不正确');
//			$('#Submit').attr('disabled','dosabled');
//			return;
//		}
//}
//
////检测地址是否正确
//function check_address(address){
////	alert(company);
////	exit;
//	var address=address.replace(/^\s*|\s*$/g,'');
//	var length=address.length;
////	alert(clength);
//	if (length==0)
//	{
//		$('#address_notice').html('地址不能为空');
//		$('#Submit').attr('disabled','disabled');
//		return;
//	}
//	if (clength<2)
//	{
//		$('#address_notice').html('地址不能小于1个汉字');
//		$('#Submit').attr('disabled','disabled');
//		return;
//	}
//	if (clength>30)
//	{
//		$('#address_notice').html('地址不能超过30个汉字');
//		$('#Submit').attr('disabled','disabled');
//		return;
//	}
//
//	$a=preg_match('/^[a-zA-Z][a-zA-Z0-9]\w{1,30}$/',company);
//		if($a) {
//			$('#address_notice').html('地址正确请继续');
//			$('#Submit').attr('disabled','');
//			return;
//		}
//		else{
//			$('#address_notice').html('地址格式不正确');
//			$('#Submit').attr('disabled','dosabled');
//			return;
//		}
//}

posted on 2016-10-09 11:02  飘渺的悠远  阅读(2184)  评论(0编辑  收藏  举报