求个一个smarty写的注册登录页面
需要一个smarty 写的注册登录页面的代码,另外需要项目建立需要的什么文件能截图,百度搜索的不能用,本人想通过这个学习下samrty,我这里先谢谢了。
回复讨论(解决方案)
在线等,可以加qq906988410
我不明白你什么意思?smarty的作用就是替换目的是更好地执行页面分离,在页面中不显示PHP代码,把PHP的变量在控制器里替换掉,像你说的那样注册页面根本用不到PHP变量,你直接写一个HTML文件当模板里面写点JAVASCRIPT验证不就完了吗?静态注册页面你可以百度下。。
smarty的作用你没弄明白,没有PHP变量根本不用替换。
我需要一个用smarty写的注册的代码 ,但是我不会用samarty,所以想要一个例子 ,参考学习一下,在网上看的介绍什么,我做了一下没有成功,感觉没有samarty的影子,所以希望大神们给一个
在线等不到了么
把你写的发上来让个大家帮你看看。
smarty就是程序模板分离没什么难的
建议看看php+smarty配置安装使用。
自己写一个smarty自定义函数,按照规范放到插件目录下就行了呗.......比如
smarty的可扩展性非常好,所以系统函数并不多,你需要什么功能,你就可以自己定义,规范也挺简单的,
比如smarty_function_自定义函数名,然后把文件名也写成这样,然后放到plugin目录下就行了。
smarty的作用不仅仅是界面分离的一种正则替换,缓存技术才是关键,不过这个也不过是filemtime和crc32等等的校验
所以smarty的关键还是学好php,,php是怎么实现的,smarty就是怎么做的
======================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
========================db.php=====================<?phpclass DB { private $host; private $db_name; private $user_name; private $password; private $conn; public function __construct($host, $user_name, $password, $db_name) { $this->host = $host; $this->user_name = $user_name; $this->password = $password; $this->db_name = $db_name; $this->connect(); } public function connect() { $this->conn = mysql_connect($this->host, $this->user_name, $this->password) or die("数据库连接失败!"); mysql_select_db($this->db_name); mysql_query("SET CHARACTER SET utf8"); } public function getObj($sql) { $rs = mysql_query($sql, $this->conn) or die (mysql_error()); $arr = array(); while ($row = mysql_fetch_array($rs)) { if (!empty($row)) $arr[] = $row; } return $arr; } public function add_data($table, $fields = array(), $values = array()) { $sql = "insert into " . $table . "(" ; for($i = 0; $i < count($fields); $i++) { if ($i < count($fields) - 1) $sql .= $fields[$i] . ','; else $sql .= $fields[$i] . ")"; } $sql .= " values ("; for($i = 0; $i < count($values); $i++) { if ($i < count($values) - 1) $sql .= "'" . $values[$i] . "'" . ','; else $sql .= "'" . $values[$i] . "')"; } mysql_query($sql, $this->conn) or die (mysql_error()); $insert_id = mysql_insert_id($this->conn) or die (mysql_error()); return $insert_id; } public function close() { mysql_close($this->conn); } }$db = new DB('localhost', 'root', '', 'test');?>==========================User类=====================================<?phprequire './Mysql/db.php';?><?phpclass User { private $user_name; private $password; private $table; function __construct($table, $user_name, $password) { $this->user_name = $user_name; $this->password = $password; $this->table = $table; } public function add_user() { global $db; $user_data = array($this->user_name, $this->password); return $db->add_data($this->table, array('user_name', 'password'), $user_data); } public function get_user($user_name) { global $db; $sql = "select * from $this->table where user_name = '" . $user_name . " '"; return $db->getObj($sql); } }?>===================user.php================================<?phpsession_start();header("Content-type: text/html; charset=utf-8"); require 'User.class.php';require './Smarty-2.6.26/libs/Smarty.class.php';$smarty = new Smarty;$smarty->compile_check = true;$smarty->debugging = false;if (isset($_REQUEST['act']) && $_REQUEST['act'] == 'register') { $user_name = $_REQUEST['user']; $password = $_REQUEST['password']; $user = new User('user', $user_name, $password); $user_arr = $user->get_user($user_name); if (empty($user_arr)) { $user->add_user(); echo "用户注册成功!" . "<br/>"; } else { echo "用户已经存在!" . "<br/>"; }} elseif (isset($_REQUEST['act']) && $_REQUEST['act'] == 'login') { $user_name = $_REQUEST['user']; $password = $_REQUEST['password']; $user = new User('user', $user_name, $password); $user_arr = $user->get_user($user_name); if (empty($user_arr)) { echo "用户不存在!" . "<br/>"; } else { if ($user_arr[0]['user_name'] == $user_name && $user_arr[0]['password'] == $password) { echo "登录成功!"; /*** * 然后就是记录session,跳转到登录成功的页面 * 把用户名使用smarty常用的assign变量方法,在注册成功的页面取出来, */ } }} elseif (isset($_REQUEST['act']) && $_REQUEST['act'] == 'login_page'){ $smarty->display('login.html');} elseif (isset($_REQUEST['act']) && $_REQUEST['act'] == 'register_page'){ $smarty->display('register.html');} else { $smarty->display('register.html');}?>==============register.html==============<!DOCTYPE html><html> <head> <title>用户注册</title> <meta charset="UTF-8"> </head> <body> <form action="/csdn/user.php" method="post" /> User Name: <input type="text" name="user" /><br/><br/> Password: <input type="password" name="password" /><br/><br/> <input type="submit" name="register" value="register"/> | <a href="/csdn/user.php?act=login_page">登录</a> <input type="hidden" name="act" value="register" /> </form> </body></html>==============login.html=========================<!DOCTYPE html><html> <head> <title>用户登录</title> <meta charset="UTF-8"> </head> <body> <form action="/csdn/user.php" method="post" /> User Name: <input type="text" name="user" /><br/><br/> Password: <input type="password" name="password" /><br/><br/> <input type="submit" name="login" value="login"/> | <a href="/csdn/user.php?act=register_page">注册</a> <input type="hidden" name="act" value="login" /> </form> </body></html>
elseif (isset($_REQUEST['act']) && $_REQUEST['act'] == 'login_page'){ $smarty->assign("title", "用户登录"); $smarty->display('login.html');} elseif (isset($_REQUEST['act']) && $_REQUEST['act'] == 'register_page'){ $smarty->assign("title", "用户注册"); $smarty->display('register.html');} else { $smarty->assign("title", "用户注册"); $smarty->display('register.html');}<html> <head> <title>{$title}</title> <!--assign进来的变量--> <strong></strong> <meta charset="UTF-8"> </head> <body> <form action="/csdn/user.php" method="post" /> User Name: <input type="text" name="user" /><br/><br/> Password: <input type="password" name="password" /><br/><br/> <input type="submit" name="login" value="login"/> | <a href="/csdn/user.php?act=register_page">注册</a> <input type="hidden" name="act" value="login" /> </form> </body></html>
你那个user类是那个文件里加的,还有你最后这段代码是加在那的,这个可以运行么
谁能告诉我么 也给分的
你那个user类是那个文件里加的,还有你最后这段代码是加在那的,这个可以运行么
最后这段就是举个assign函数的例子而已
smarty 没有什么难的么,头疼 东西多啊
smarty 没有什么难的么,头疼 东西多啊
模板的原理大多数都是一样 就是查找替换, 然后就需要PHP的数组和字符串处理知识,学会了这两个就能做功能了,PHP上手就是这么简单
你这个不能用 的 但是分还是给你
亲,可以用,这是我写完经过调试验证的

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.
