龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

PHP+jQuery 注册模块开发详解(9)

时间:2014-10-15 11:00来源:网络整理 作者:网络 点击:
分享到:
activation.php: php session_start();header('Content-type:text/html;charset=utf-8');include_once 'conn/conn.php';$table = "user";if(!empty($_GET['name']) !is_null($_GET['name'])){ //urlencode会对字符

activation.php:

<?php 
session_start();
header('Content-type:text/html;charset=utf-8');
include_once 'conn/conn.php';

$table = "user";

if(!empty($_GET['name']) && !is_null($_GET['name'])){
          
  //urlencode会对字符串进行转义。所以这里要进行处理
  if(get_magic_quotes_gpc()){
  
    $getname = stripslashes(urldecode($_GET['name']));
  }else{
  
    $getname = urldecode($_GET['name']);
  }

  //urldecode反转url中的中文编码
  $sql = "select * from ".$table." where uname='".$getname."' and activekey='".$_GET['k']."'";

  $num = $conne->getRowsNum($sql);
  if($num>0){
    
    $rs = $conne->getRowsRst($sql);  

    //此时数据库里的字符串是不会带反斜杠的  
    //因此要为下面的SQL语句加上反斜杠
    $rsname = addslashes($rs['uname']);

    $upnum = $conne->uidRst("update ".$table." set active = 1 where uname = '".$rsname."' and activekey = '".$rs['activekey']."'");

    if($upnum>0){
      
      $_SESSION['name'] = urldecode($getname);
      echo "<script>alert('您已成功激活');window.location.href='main.php';</script>";
    }else{
      
      echo "<script>alert('您已经激活过了');window.location.href='main.php';</script>";
    }
  }else{
    
    echo "<script>alert('激活失败');window.location.href='templets/register.html';</script>";
  }
}

?>

关于注册成功后的邮件页和跳转页,这里不做了。

关于数据库防注入的几种方式magic_quote_gpc,addslashes/stripslashes,mysql_real_eascpae_string,我做了一张表格

数据库设计:

user表

create table user (id int primary key auto_increment,
uname varchar(14) not null default '',
upwd char(32) not null default '',
uemail varchar(50) not null default '',
active tinyint(4) default '0',
activekey char(32) not null defalut '')engine=innodb default charset=utf8

说明:md5的长度是32。

模块的目录结构如下:

ROOT:
├─conn
│ ├─conn.php

├─templets
│ ├─css
│ │ ├─common.css
│ │ ├─register.css
│ │
│ ├─images
│ │
│ └─js
│ ├─jquery-1.8.3.min.js
│ ├─register.js
│ ├─emailup.js

├─chkname.php
├─chkemail.php
├─valcode.php
├─register_chk.php
├─activation.php
├─arial.ttf

└─Zend

模块至此结束。

精彩图集

赞助商链接