PHP开发实例大全(提高卷) 中文完整pdf扫描版[244MB]
一、图解
二、描述
1. 前端输入手机号
2. 验证手机是否注册
3. php代码中生成验证码
4. php代码,通过短信平台接口(api),发送验证码和其他内容到短信平台,在由短信平台发送到用户手机短信,同时把此验证码记录保存到自己建立的本地数据库
5. 用户获取验证码,输入到注册表单并提交
6. php代码验证表单提交的验证码,如果和数据库相符,祝贺注册成功
三、核心代码 ecshop中添加手机验证为实例的函数
function sendSMS ($mobile, $content, $time = '', $mid = '') { $content = iconv('utf-8', 'gbk', $content); $http = 'http://http.yunsms.cn/tx/'; // 短信接口 $uid = $GLOBALS['_CFG']['ecsdxt_user_name']; // 用户账号 $pwd = $GLOBALS['_CFG']['ecsdxt_pass_word']; // 密码 $data = array( 'uid' => $uid, // 用户账号 'pwd' => strtolower(md5($pwd)), // MD5位32密码,密码和用户名拼接字符 'mobile' => $mobile, // 号码 'content' => $content, // 内容 'time' => $time, // 定时发送 'mid' => $mid ); $re = postSMS($http, $data); // POST方式提交 $re_t = substr(trim($re), 3, 3); if(trim($re) == '100' || $re_t == '100') { return true; } else { return false; } } function postSMS ($url, $data = '') { $row = parse_url($url); $host = $row['host']; $port = $row['port'] ? $row['port'] : 80; $file = $row['path']; while(list($k, $v) = each($data)) { $post .= rawurlencode($k) . "=" . rawurlencode($v) . "&"; // 转URL标准码 } $post = substr($post, 0, - 1); $len = strlen($post); $fp = @fsockopen($host, $port, $errno, $errstr, 10); if(! $fp) { return "$errstr ($errno)\n"; } else { $receive = ''; $out = "POST $file HTTP/1.1\r\n"; $out .= "Host: $host\r\n"; $out .= "Content-type: application/x-www-form-urlencoded\r\n"; $out .= "Connection: Close\r\n"; $out .= "Content-Length: $len\r\n\r\n"; $out .= $post; fwrite($fp, $out); while(! feof($fp)) { $receive .= fgets($fp, 128); } fclose($fp); $receive = explode("\r\n\r\n", $receive); unset($receive[0]); return implode("", $receive); } }
转载请注明:谷谷点程序 » php 手机短信验证码 ecshop会员注册短信验证码