Rumah >pembangunan bahagian belakang >tutorial php >求个一个smarty写的登记登录页面

求个一个smarty写的登记登录页面

WBOY
WBOYasal
2016-06-13 12:11:11949semak imbas

求个一个smarty写的注册登录页面
需要一个smarty 写的注册登录页面的代码,另外需要项目建立需要的什么文件能截图,百度搜索的不能用,本人想通过这个学习下samrty,我这里先谢谢了。
------解决思路----------------------
自己写一个smarty自定义函数,按照规范放到插件目录下就行了呗.......比如   函数名是login  后面的几个作为参数


smarty的可扩展性非常好,所以系统函数并不多,你需要什么功能,你就可以自己定义,规范也挺简单的,
比如smarty_function_自定义函数名,然后把文件名也写成这样,然后放到plugin目录下就行了。

smarty的作用不仅仅是界面分离的一种正则替换,缓存技术才是关键,不过这个也不过是filemtime和crc32等等的校验
------解决思路----------------------
======================sql========================
CREATE TABLE `user` (
  `user_id` int(5) NOT NULL AUTO_INCREMENT,
  `user_name` varchar(20) NOT NULL,
  `password` varchar(20) NOT NULL,
  PRIMARY KEY (`user_id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8



<br />========================db.php=====================<br /><?php<br />class DB {<br />    private $host;<br />    private $db_name;<br />    private $user_name;<br />    private $password;<br />    private $conn;<br />    <br />    public function __construct($host, $user_name, $password, $db_name) {<br />        $this->host = $host;<br />        $this->user_name = $user_name;<br />        $this->password = $password;<br />        $this->db_name = $db_name;<br />        $this->connect();<br />    }<br />    public function connect() {<br />        $this->conn = mysql_connect($this->host, $this->user_name, $this->password) or die("数据库连接失败!");<br />        mysql_select_db($this->db_name);<br />        mysql_query("SET CHARACTER SET utf8");<br />    }<br />    public function getObj($sql) {<br />        $rs = mysql_query($sql, $this->conn) or die (mysql_error());<br />        $arr = array();<br />        while ($row = mysql_fetch_array($rs)) {<br />            if (!empty($row))<br />                $arr[] = $row;<br />        }<br />        return $arr;<br />    }<br />    public function add_data($table, $fields = array(), $values = array()) {<br />        $sql = "insert into " .  $table . "(" ;<br />        for($i = 0; $i < count($fields); $i++) {<br />            if ($i < count($fields) - 1)<br />                $sql .= $fields[$i] . ',';<br />            else<br />                $sql .= $fields[$i] . ")";<br />        }<br />        $sql .= " values (";<br />        for($i = 0; $i < count($values); $i++) {<br />            if ($i < count($values) - 1)<br />                $sql .= "'" . $values[$i] . "'" . ',';<br />            else<br />                $sql .= "'" . $values[$i] . "')";<br />        }<br />        mysql_query($sql, $this->conn) or die (mysql_error());<br />        $insert_id = mysql_insert_id($this->conn) or die (mysql_error());<br />        return $insert_id;<br />    }<br />    public function close() {<br />        mysql_close($this->conn);<br />    }<br />   <br />}<br />$db = new DB('localhost', 'root', '', 'test');<br />?><br />==========================User类=====================================<br /><?php<br />require './Mysql/db.php';<br />?><br /><br /><?php<br />class User {<br />    private $user_name;<br />    private $password;<br />    private $table;<br />    function __construct($table, $user_name, $password) {<br />        $this->user_name = $user_name;<br />        $this->password = $password;<br />        $this->table = $table;<br />    }<br />    public function add_user() {<br />        global $db;<br />        $user_data = array($this->user_name, $this->password);<br />        return $db->add_data($this->table, array('user_name', 'password'), $user_data);<br />    }<br />    public function get_user($user_name) {<br />        global $db;<br />        $sql = "select * from $this->table where user_name = '" . $user_name . " '";<br />        return $db->getObj($sql);<br />    }<br />    <br />}<br />?><br /><br />===================user.php================================<br /><?php<br />session_start();<br />header("Content-type: text/html; charset=utf-8"); <br />require 'User.class.php';<br />require './Smarty-2.6.26/libs/Smarty.class.php';<br />$smarty = new Smarty;<br />$smarty->compile_check = true;<br />$smarty->debugging = false;<br /><br />if (isset($_REQUEST['act']) && $_REQUEST['act'] == 'register') {<br />    $user_name = $_REQUEST['user'];<br />    $password = $_REQUEST['password'];<br />    $user = new User('user', $user_name, $password);<br />    $user_arr = $user->get_user($user_name);<br />    if (empty($user_arr)) {<br />        $user->add_user();<br />        echo "用户注册成功!" . "<br/>";<br />    } else {<br />        echo "用户已经存在!" . "<br/>";<br />    }<br />} elseif (isset($_REQUEST['act']) && $_REQUEST['act'] == 'login') {<br />    $user_name = $_REQUEST['user'];<br />    $password = $_REQUEST['password'];<br />    $user = new User('user', $user_name, $password);<br />    $user_arr = $user->get_user($user_name);<br />    if (empty($user_arr)) {        <br />        echo "用户不存在!" . "<br/>";<br />    } else {<br />        if ($user_arr[0]['user_name'] == $user_name && $user_arr[0]['password'] == $password) {<br />            echo "登录成功!"; <br />            /***<br />             * 然后就是记录session,跳转到登录成功的页面<br />             * 把用户名使用smarty常用的assign变量方法,在注册成功的页面取出来,<br />             */<br />        }<br />    }<br />} elseif (isset($_REQUEST['act']) && $_REQUEST['act'] == 'login_page'){<br />    $smarty->display('login.html');<br />} elseif (isset($_REQUEST['act']) && $_REQUEST['act'] == 'register_page'){<br />    $smarty->display('register.html');<br />} else {<br />    $smarty->display('register.html');<br />}<br /><br />?><br /><br /><br />==============register.html==============<br /><!DOCTYPE html><br /><html><br />    <head><br />        <title>用户注册</title><br />        <meta charset="UTF-8"><br />    </head><br />    <body><br />        <form action="/csdn/user.php" method="post" /><br />        User Name: <input type="text" name="user" /><br/><br/><br />        Password:   <input type="password" name="password" /><br/><br/><br />        <input type="submit" name="register" value="register"/> <br><font color='#FF8000'>------解决思路----------------------</font><br> <a href="/csdn/user.php?act=login_page">登录</a>        <br />        <input type="hidden" name="act" value="register" /><br />        </form><br />    </body><br /></html><br /><br />==============login.html=========================<br /><!DOCTYPE html><br /><html><br />    <head><br />        <title>用户登录</title><br />        <meta charset="UTF-8"><br />    </head><br />    <body><br />        <form action="/csdn/user.php" method="post" /><br />        User Name: <input type="text" name="user" /><br/><br/><br />        Password:  <input type="password" name="password" /><br/><br/><br />        <input type="submit" name="login" value="login"/> <br><font color='#FF8000'>------解决思路----------------------</font><br> <a href="/csdn/user.php?act=register_page">注册</a>        <br />        <input type="hidden" name="act" value="login" /><br />        </form><br />    </body><br /></html><br /><br /><br />

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn