登录、注册界面 <!DOCTYPE html> <!--[if lt IE 7 ]> <html class="no-js ie6 lt8"> <![endif]--> <!--[if IE 7 ]> <html class="no-js ie7 lt8"> <![endif]--> <!--[if IE 8 ]> <html class="no-js ie8 lt8"> <![endif]--> <!--[if IE 9 ]> <html class="no-js ie9"> <![endif]--> <!--[if (gt IE 9)|!(IE)]><!--> <html> <!--<![endif]--> <head> <meta charset="UTF-8" /> <!-- <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> --> <title>Login and Registration Form with HTML5 and CSS3</title> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content="Login and Registration Form with HTML5 and CSS3" /> <meta name="keywords" content="html5, css3, form, switch, animation, :target, pseudo-class" /> <meta name="author" content="Codrops" /> <link rel="shortcut icon" href="../favicon.ico"> <link rel="stylesheet" type="text/css" href="css/demo.css" /> <link rel="stylesheet" type="text/css" href="css/style.css" /> <link rel="stylesheet" type="text/css" href="css/animate-custom.css" /> </head> <body> <div> <header> <h1>It's IMOOC<span>This Is King Show Time</span></h1> <nav> <span>Click <strong>"Join us"</strong> to Register the Imooc</span> </nav> </header> <section> <div id="container_demo" > <a id="toregister"></a> <a id="tologin"></a> <div id="wrapper"> <div id="login" class="animate form"> <form action="doAction.php?act=login" autocomplete="on" method="post"> <h1>Log in</h1> <p> <label for="username" data-icon="u" > Your username </label> <input id="username" name="username" required="required" type="text" placeholder="My Username"/> </p> <p> <label for="password" data-icon="p"> Your password </label> <input id="password" name="password" required="required" type="password" placeholder="*****" /> </p> <p> <input type="checkbox" name="loginkeeping" id="loginkeeping" value="loginkeeping" /> <label for="loginkeeping">Keep me logged in</label> </p> <p class="login button"> <input type="submit" value="Login" /> </p> <p> Not a member yet ? <a href="#toregister">Join us</a> </p> </form> </div> <div id="register" class="animate form"> <form action="doAction.php?act=reg" autocomplete="on" method="post"> <h1> Sign up </h1> <p> <label for="usernamesignup" data-icon="u">Your username</label> <input id="usernamesignup" name="username" required="required" type="text" placeholder="Mr.King" /> </p> <p> <label for="emailsignup" data-icon="e" > Your email</label> <input id="emailsignup" name="email" required="required" type="email" placeholder="Mr.King@mail.com"/> </p> <p> <label for="passwordsignup" data-icon="p">Your password </label> <input id="passwordsignup" name="password" required="required" type="password" placeholder="******"/> </p> <p class="signin button"> <input type="submit" value="Sign up"/> </p> <p> Already a member ? <a href="#tologin"> Go and log in </a> </p> </form> </div> </div> </div> </section> </div> </body> </html>
php代码 <?php header('content-type:text/html;charset=utf-8'); //1.包含所需文件 error_reporting(0); require_once 'swiftmailer-master/lib/swift_required.php'; require_once 'PdoMySQL.class.php'; require_once 'config.php'; require_once 'pwd.php'; //2.接收信息 $act=$_GET['act']; $username=addslashes($_POST['username']); $password=md5($_POST['password']); $email=$_POST['email']; $table='user'; //3.获得链接对象 $PdoMySQL=new PdoMySQL(); if($act==='reg'){ $regtime=time(); //完成注册的功能 $token=md5($username.$password.$regtime); $token_exptime=$regtime+24*3600;//过时时间 $data=compact('username','password','email','token','token_exptime','regtime'); $res=$PdoMySQL->add($data, $table); $lastInsertId=$PdoMySQL->getLastInsertId(); if($res){ //发送邮件,以QQ邮箱为例 //配置邮件服务器,获得传输对象 $transport=Swift_SmtpTransport::newInstance('smtp.qq.com',25); //设置登录账号和密码 $transport->setUsername('704568245@qq.com'); $transport->setPassword($emailPassword); //获得发送邮件对象Swift_Mailer对象 $mailer=Swift_Mailer::newInstance($transport); //获得邮件信息对象 $message=Swift_Message::newInstance(); //设置管理员的信息 $message->setFrom(array('704568245@qq.com'=>'动物管理系统')); //将邮件发给谁 $message->setTo(array($email=>'感谢你注册宠物系统')); //设置邮件主题 $message->setSubject('激活邮件'); $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."?act=active&token={$token}"; $urlencode=urlencode($url); $str=<<<EOF 亲爱的{$username}您好~!感谢您注册咱们网站<br/> 请点击此连接激活账号便可登录!<br/> <a href="{$url}">{$urlencode}</a> <br/> 若是点此连接无反映,能够将其复制到浏览器中来执行,连接的有效时间为24小时。 EOF; $message->setBody("{$str}",'text/html','utf-8'); try{ if($mailer->send($message)){ echo "恭喜您{$username}注册成功,请到邮箱激活以后登录<br/>"; echo '3秒钟后跳转到登录页面'; echo '<meta http-equiv="refresh" content="3;url=index.php#tologin"/>'; }else{ $PdoMySQL->delete($table,'id='.$lastInsertId); echo '注册失败,请从新注册'; echo '3秒钟后跳转到注册页面'; echo '<meta http-equiv="refresh" content="3;url=index.php#toregister"/>'; } }catch(Swift_ConnectionException $e){ echo '邮件发送错误'.$e->getMessage(); } }else{ echo '用户注册失败,3秒钟后跳转到注册页面'; echo '<meta http-equiv="refresh" content="3;url=index.php#toregister"/>'; } }elseif($act==='login'){ //完成登录的功能 $row=$PdoMySQL->find($table,"username='{$username}' AND password='{$password}'",'status'); if($row['status']==0){ echo '请先激活再登录'; echo '<meta http-equiv="refresh" content="3;url=index.php#tologin"/>'; }else{ echo '登录成功,3秒钟后跳转到首页'; echo '<meta http-equiv="refresh" content="3;url=http://www.imooc.com"/>'; } }elseif($act==='active'){ $token=addslashes($_GET['token']); $row=$PdoMySQL->find($table,"token='{$token}' AND status=0",array('id','token_exptime')); $now=time(); if($now>$row['token_exptime']){ echo '激活时间过时,请从新登录激活'; }else{ $res=$PdoMySQL->update(array('status'=>1),$table,'id='.$row['id']); if($res){ echo '激活成功,3秒钟后跳转到登录页面'; echo '<meta http-equiv="refresh" content="3;url=index.php#tologin"/>'; }else{ echo '激活失败,请从新激活'; echo '<meta http-equiv="refresh" content="3;url=index.php"/>'; } } } <?php /* * This file is part of SwiftMailer. * (c) 2004-2009 Chris Corbyn * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /* * Autoloader and dependency injection initialization for Swift Mailer. */ if (class_exists('Swift', false)) { return; } // Load Swift utility class require dirname(__FILE__) . '/classes/Swift.php'; if (!function_exists('_swiftmailer_init')) { function _swiftmailer_init() { require dirname(__FILE__) . '/swift_init.php'; } } // Start the autoloader and lazy-load the init script to set up dependency injection Swift::registerAutoload('_swiftmailer_init');
其中在进行mysql数据表删除数据的时候没想到delete table 会在日志中有记录,占用空间php
后来想到用truncate
删除数据,且不残留记录css
-- 清空所有数据,不写日志,不可恢复,速度极快
truncate
table
表名;
-- 清空所有数据,写日志,数据可恢复,速度慢
delete
from
表名
html