php168 邮箱激活改为手机激活的实现方法
意思就是让会员注册后进入手机短信激活界面, 先输入手机号码,点击提交后会收到一个短信(内容是验证码),然后在手机短信激活界面输入正确的验证码才可激活。
当然了,前提是你已经设置好相关的手机短信接口资料配置,否则一切也是白搭。
先看一下手机短信的接口资料配置,如下图:
修改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("当前帐号已激活!");
}elseif(!$atc_mobphone){
showerr("请输入手机号码!");
}
if( !ereg("^1(3|5|8)[0-9]{9}$",$atc_mobphone) ){
showerr("号码不符合规则");
}
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("./","系统已经成功发送验证码到:“{$atc_mobphone}”,请注意查收!",5);
}else{
showerr("短信发送失败,请检查短信接口,是否帐号有误,或者是余额不足!");
}
}
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">发送激活验证码</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;
?>
-->