search
HomeBackend DevelopmentPHP Tutorial求个一个smarty写的登记登录页面

求个一个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 />

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.