php验证手机
‘壹’ php需要判断手机号码
$n=count($mobile);
for($i=0;$i<$n;$i++)
{
if(preg_match("/^13[0-9]{1}[0-9]{8}$|15[0189]{1}[0-9]{8}$|189[0-9]{8}$/",$mobile[$n]
))
{
echo $mobile[$n];
}
}
‘贰’ 在 PHP 开发中如何判断用户是否使用手机
PHP通过内置全局变量$_SERVER['HTTP_USER_AGENT']来获取用户信息,包括浏览器信息,操作系统等;判断是否是手机还是电脑终端访问,只需判断他的$_SERVER['HTTP_USER_AGENT']信息是否存在手机终端类型即可。示例如下:
<?php
//1.获取用户浏览器信息等;
$user_agent=$_SERVER['HTTP_USER_AGENT'];
//2.列举常用手机终端类型
$mobile_agents=array("240x320","acer","acoon","acs-","abacho","ahong","airness","alcatel","amoi",
"android","anywhereyougo.com","applewebkit/525","applewebkit/532","asus","audio",
"au-mic","avantogo","becker","benq","bilbo","bird","blackberry","blazer","bleu",
"cdm-","compal","coolpad","danger","dbtel","dopod","elaine","eric","etouch","fly",
"fly_","fly-","go.web","goodaccess","gradiente","grundig","haier","hedy","hitachi",
"htc","huawei","hutchison","inno","ipad","ipaq","iphone","ipod","jbrowser","kddi",
"kgt","kwc","lenovo","lg","lg2","lg3","lg4","lg5","lg7","lg8","lg9","lg-","lge-","lge9","longcos","maemo",
"mercator","meridian","micromax","midp","mini","mitsu","mmm","mmp","mobi","mot-",
"moto","nec-","netfront","newgen","nexian","nf-browser","nintendo","nitro","nokia",
"nook","novarra","obigo","palm","panasonic","pantech","philips","phone","pg-",
"playstation","pocket","pt-","qc-","qtek","rover","sagem","sama","samu","sanyo",
"samsung","sch-","scooter","sec-","sendo","sgh-","sharp","siemens","sie-","softbank",
"sony","spice","sprint","spv","symbian","tablet","talkabout","tcl-","teleca","telit",
"tianyu","tim-","toshiba","tsm","up.browser","utec","utstar","verykool","virgin",
"vk-","voda","voxtel","vx","wap","wellco","wigbrowser","wii","windowsce",
"wireless","xda","xde","zte");
foreach($mobile_agentsas$device){
if(stristr($user_agent,$device)){
//手机访问
$is_mobile=true;
break;
}
}
//判断手机标识是否为真
if($is_mobile){
echo"手机访问!";
}else{
echo"电脑访问!";
}
?>
‘叁’ php实现手机验证码验证注册功能的逻辑是怎样的
手机注册验证逻辑是这样的:
首先要找短信服务商如:梦网、云信使、互亿无线等等申请短信发送接口。
网站实现流程如下:
第一步:用户注册时输入手机号,网站首先要通过JS或者ajax+php验证这个号码是不是正确的手机号。
第二步:用户点击发送手机验证码,通过ajax把手机号传到php,这时php生成一个随机的验证码保存在session中,然后通过短信接口把这个验证码发送到这个手机号中。
第三步:用户输入手机收到的验证码注册。网站用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();
}
‘伍’ php中输入一个手机号判断是否合理代码
if(preg_match("/1[3458]{1}\d{9}$/",$phonenumber)){
echo "是手机号码";
}else{
echo "不是手机号码";
}
网络搜索 PHP正则 手机号码
‘陆’ PHP问题:如何判断对方输入的手机号是11位呢
if(preg_match('/^(131|132)\d{8}$/','13123321123'))
{
//11位并且是131或者132开头的
}
else
{
//不符合条件
}
To MoontoC:
正则的优势是简单、灵活、严谨
举个很简单的例子,如果用户输入的是
13134567890.01
13134567890ab
用浮点判断自然导致数据库操作错误
如果要必免这样的错误发生,自然又要用到字符串操作
strlen($num) == 11
而即使是上面这个函数,也不一定是正确的。考虑
$num = '1.313456e10';
另外,如果条件再改改,要加入137,138开头的呢,
而字符串函数还要判断每一位是不是数字吧。
至于效率,在没装Zend Optimizer的情况下每秒三十万次以上已经可以满足绝大多数情况了。
‘柒’ php判断是否为手机
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
$uachar = "/(nokia|sony|ericsson|mot|samsung|sgh|lg|philips|panasonic|alcatel|lenovo|cldc|midp|mobile)/i";
if(($ua == '' || preg_match($uachar, $ua))&& !strpos(strtolower($_SERVER['REQUEST_URI']),'wap'))
{
echo '手机访问';
}
‘捌’ 怎么用php实现手机注册和手机验证
在网络找个短信服务提供商,大概0.5分一条,这种稳定些。30秒以内收到。验证就和验证码一样处理了。
‘玖’ php 同时验证电话号码和手机号码的正则表达式,请写下号码格式
悬赏也太低了点吧: 提供一个吧,追加悬赏啊。。。
preg_match('%^(?:(?:0[0-9]{2,3}[0-9]{7,8})|(?:1[3|4|5|8][0-9]{9}))$%', $subject,$c);
var_mp($c);
‘拾’ 用PHP如何做一个手机发送验证码存储,用户接受后再输入验证
发短信得找移动,联通之类的合作,或者简单的就是淘宝 卖的别人提供的接口。
验证码的话就容易了 存session 就设置session_cache_expire() 数据库就加个 过期时间的字段 例如 expiretime int unsigned not null 到时候取出来比较就行