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

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi


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

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Atom editor mac version download
The most popular open source editor

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
