php168 郵箱激活改為手機激活的實現(xiàn)方法
意思就是讓會員注冊后進入手機短信激活界面, 先輸入手機號碼,點擊提交后會收到一個短信(內(nèi)容是驗證碼),然后在手機短信激活界面輸入正確的驗證碼才可激活。
當(dāng)然了,前提是你已經(jīng)設(shè)置好相關(guān)的手機短信接口資料配置,否則一切也是白搭。
先看一下手機短信的接口資料配置,如下圖:
修改do/activate.php 的代碼為:
<?php
require(dirname(__FILE__)."/"."global.php");
if($action=='send')
{
$rs=$userDB->get_allInfo($atc_username,'name');
if(!$rs){
showerr("帳號不存在!");
}elseif($rs[yz]){
showerr("當(dāng)前帳號已激活!");
}elseif(!$atc_mobphone){
showerr("請輸入手機號碼!");
}
if( !ereg("^1(3|5|8)[0-9]{9}$",$atc_mobphone) ){
showerr("號碼不符合規(guī)則");
}
if(!$webdb[mymd5])
{
$webdb[mymd5]=rands(10);
$db->query("REPLACE INTO {$pre}config (`c_key`,`c_value`) VALUES ('mymd5','$webdb[mymd5]')");
write_file(PHP168_PATH."php168/config.php","$webdb['mymd5']='$webdb[mymd5]';",'a');
}
$md5_id=mymd5("{$rs[username]} {$rs[password]}");
$Title="你好,這是來自“{$webdb[webname]}”的注冊驗證碼:{$md5_id}";
if( sms_send($atc_mobphone, $Title )===1 ){
refreshto("./","系統(tǒng)已經(jīng)成功發(fā)送驗證碼到:“{$atc_mobphone}”,請注意查收!",5);
}else{
showerr("短信發(fā)送失敗,請檢查短信接口,是否帳號有誤,或者是余額不足!");
}
}
elseif($job=='activate')
{
$rs=$userDB->get_allInfo($atc_username,'name');
$md5_id=mymd5("{$rs[username]} {$rs[password]}");
if(!$atc_md5id){
showerr("請輸入驗證碼 $md5_id !");
}
if($atc_md5id!=$md5_id){
showerr("請輸入正確的驗證碼!");
}
list($username,$password)=explode(" ",mymd5($md5_id,'DE'));
$rs=$userDB->get_allInfo($username,'name');
if($rs&&$rs[password]==$password)
{
$db->query("UPDATE {$pre}memberdata SET `yz`='1' WHERE uid='$rs[uid]'");
refreshto("login.php","恭喜你,帳號“{$username}”激活成功,請立即登錄體驗會員特有的功能!",10);
}
else
{
showerr("帳號激活失敗!");
}
}
if($username){
$rs=$userDB->get_allInfo($username,'name');
$mobphone=$rs[mobphone];
}
require(PHP168_PATH."inc/head.php");
require(html("activate"));
require(PHP168_PATH."inc/foot.php");
?>
然后修改template/default/activate.htm 的代碼為:
<!--
<?php
print <<<EOT
-->
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" class="MainTable">
<tr>
<td height="393" valign="top" class="Main">
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" class="dragTable" style="display:$hide_listpic">
<form name="form1" method="post" action="?action=send">
<tr>
<td class="head">
<h3 class="L"></h3>
<span class="TAG">發(fā)送激活驗證碼</span>
<h3 class="R"></h3>
</td>
</tr>
<tr>
<td class="middle" align="center">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" height="62">要激活的帳號是:
<input type="text" name="atc_username" value="$username">
<br>
請輸入手機號碼:
<input type="text" name="atc_mobphone" value="$mobphone">
<br>
<br>
<input type="submit" name="Submit" value="提交" class="button">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="foot">
<h3 class="L"></h3>
<h3 class="R"></h3>
</td>
</tr>
</form>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" class="dragTable" style="display:$hide_listpic">
<form name="form2" method="post" action="?job=activate">
<tr>
<td class="head">
<h3 class="L"></h3>
<span class="TAG">激活帳號</span>
<h3 class="R"></h3>
</td>
</tr>
<tr>
<td class="middle" align="center">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" height="62">
要激活的帳號是:
<input type="text" name="atc_username" value="$username">
<br>
請輸入驗證碼:
<input type="text" name="atc_md5id" value="">
<br>
<input type="submit" name="Submit2" value="提交" class="button">
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="foot">
<h3 class="L"></h3>
<h3 class="R"></h3>
</td>
</tr>
</form>
</table>
</td>
</tr>
</table>
<!--
EOT;
?>
-->