㈠ 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中輸入一個手機號判斷是否合理代碼
if(preg_match("/1[3458]{1}\d{9}$/",$phonenumber)){
echo "是手機號碼";
}else{
echo "不是手機號碼";
}
網路搜索 PHP正則 手機號碼
㈢ php實現手機驗證碼驗證注冊功能的邏輯是怎樣的
手機注冊驗證邏輯是這樣的:
首先要找簡訊服務商如:夢網、雲信使、互億無線等等申請簡訊發送介面。
網站實現流程如下:
第一步:用戶注冊時輸入手機號,網站首先要通過JS或者ajax+php驗證這個號碼是不是正確的手機號。
第二步:用戶點擊發送手機驗證碼,通過ajax把手機號傳到php,這時php生成一個隨機的驗證碼保存在session中,然後通過簡訊介面把這個驗證碼發送到這個手機號中。
第三步:用戶輸入手機收到的驗證碼注冊。網站用session中的驗證碼和用戶輸入的驗證碼比較。
㈣ 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需要判斷手機號碼
$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問題:如何判斷對方輸入的手機號是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實現手機注冊和手機驗證
在網路找個簡訊服務提供商,大概0.5分一條,這種穩定些。30秒以內收到。驗證就和驗證碼一樣處理了。
㈧ 在 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如何做一個手機發送驗證碼存儲,用戶接受後再輸入驗證
發簡訊得找移動,聯通之類的合作,或者簡單的就是淘寶 賣的別人提供的介面。
驗證碼的話就容易了 存session 就設置session_cache_expire() 資料庫就加個 過期時間的欄位 例如 expiretime int unsigned not null 到時候取出來比較就行
㈩ 如何實現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();
}