登錄、註冊界面 <!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