php 发送手机验证码
2024-09-07 13:29:06
嗯哼,做为一个好的程序猿,一定要给顾客爸爸剁手的时候,充分的告诉他,你剁完手了,所以不只有邮件通知还要有手机短信的通知,今天就来写一下php发送验证码
1、首先我就写了几个个方法,因为配置在后台,直接取就好了,有的需要表单提交过来,只需要接收一下,把对应的值写一下就好了,这个函数或许麻烦一点,但是仔细看,不麻烦的
get_captcha()函数,直接访问,就能发送验证码
//发送验证码
function get_captcha1(){
$phone="";
if(!preg_match("/^1[3456789]{1}\d{9}$/",$phone)){
exit("手机号格式不正确");
}
if(time()-$_SESSION['last_send_time']<){
exit("短信发送太频繁了!");
}
if($phone ){
$r = rand(,);
$content = '本次验证码为:'.$r.",十分钟内有效.【新华好房】";
$rs = sendSms($phone,$content);//调用函数sendSms()
if($rs==true){
$_SESSION['last_send_time'] = time();//将时间存进session
echo 'ok';exit("");
}
}
}
sendSms()函数
function sendSms($mobile,$msg){
if(!$mobile && !$msg){
return false;
}
$post="action=send&userid=376&account=zyjtz&password=kk123321yy&mobile=$mobile&content=$msg&sendTime=&extno=";
//组成链接,把对应的userid和account写对,其实不同的短信接口有不同的方式,有的话根据供应商给的接口来写
$xml=http_post('http://115.29.242.32:8888/sms.aspx', $post);//调用http_post()函数
$res = @simplexml_load_string($xml,NULL,LIBXML_NOCDATA);
$res = json_decode(json_encode($res),true);
if($res['returnstatus']=='Success'){
return true;
}
return false;
//print_test($res);
}
http_post()函数
function http_post($url, $post = '', $timeout = , $times = ) {
$stream = stream_context_create(array('http' => array('header' => 'Content-type: application/x-www-form-urlencoded', 'method' => 'POST', 'content' => $post, 'timeout' => $timeout)));
while($times-- > ) {
$s = file_get_contents($url, NULL, $stream, , );
if($s !== FALSE) return $s;
}
return FALSE;
}
先到这里,我们今天下班了,劳动节快乐,回来如果我还能记得,写的详细一点,这样只能发送验证码,里面很多东西没加,比如不能多次发送,防止注册机注册等,所以呢,回来再更新。
最新文章
- Sql Server之旅——第七站 为什么都说状态少的字段不能建索引
- 值得订阅的Android 开发者博客
- 【无聊放个模板系列】HDU 3068 MANACHER
- 关于 RecastNavigation 寻路结果异常的问题。
- libevent使用之安装(一)
- C/C++语言学习——内存分配管理
- hunnu11543:小明的烦恼——分糖果
- CAN总线基础
- [tableView dequeueReusableCellWithIdentifier:CellIdentifier] 后面forIndexPath:indexPath参数的解释
- [LeetCode] Serialize and Deserialize N-ary Tree N叉搜索树的序列化和去序列化
- 【leetcode】427. Construct Quad Tree
- 关于js中的时间——计算时间差等
- 22.纯 CSS 创作出美丽的彩虹条纹文字
- Jmeter JDBC的使用
- 接收一条音频(系统音频)彩信,点菜单键选择View slideshow,不能播放,提示是否导入vCard
- (1)I/O流 (2)线程
- php之快速入门学习-5(常量)
- 随机数Math.random()公式
- Python学习---面向对象的学习[深入]
- SaltStack自动化安装zabbix-server
热门文章
- memcached和redis对比
- WPF MVVM 键盘按键事件绑定
- webrtc vp8与h264 sdp文件解读
- mssql 数据库 基本知识
- rancher布控集群启动失败
- maven web报错:org.apache.jasper.JasperException: Unable to compile class for JSP
- Educational Codeforces Round 82 (Rated for Div. 2)D(模拟)
- Pandas数据结构(一)——Pandas Series
- mediasoup-demo安装记录
- C++ split分割字符串函数