重要:本文最后更新于2018-11-13 13:42:11
,某些文章具有时效性,若有错误或已失效,请在下方留言或联系九月网。
前面三篇文章我们已经成功将用户激活的相关数据写进了数据库里,并以邮件的方式给用户发送了一条带有激活数据的get链接。形如:http://xxxxx.com/jihuo.php?id=xx&token=xxxxxxxxxxx
当用户点击后,就会将数据提交到jihuo.php页面。所以,我们需要在jihuo.php页面中接收数据,并判断是否予以激活。
- 创建jihuo.php文件,位与网站根目录下。
- 接收传递过来的get数据。代码如下:
if(isset($_GET[ 'token'])&&isset($_GET[ 'user_id'])) { $token=$_GET[ 'token']; $user_id=$_GET[ 'user_id']; }else{ echo "数据接收失败"; }
- 获取服务器时间与数据库中对应用户的激活时间
- 计算时间是否超过指定时间差。详情见:九月网——计算时间差
- 链接数据库,更新数据。
jihuo.php文件代码如下:
<?php if(isset($_GET[ 'token'])&&isset($_GET[ 'user_id'])) { $token=$_GET[ 'token']; $user_id=$_GET[ 'user_id']; $con=mysql_connect("localhost", "root", "800820"); if (!$con) { die("数据库连接失败: " . mysql_error()); }else{ mysql_select_db("wptest",$con); $sql="select * from wp_users where id='".$user_id."'"; $result=mysql_query($sql); while($row=mysql_fetch_array($result)){ $cxtoken=$row['token']; $cxtoken_time=$row['token_time']; } if($token==$cxtoken){ if(isouttime($cxtoken_time,gettime())
实测效果图: