Need a Smarty Write the login page code, in addition to the project needs to establish what the file can, Baidu Search can not be used, I want to learn through this samrty, I here first thank you.
Reply to discussion (solution)
Online, etc., can be added qq906988410
I don't know what you mean. Smarty's role is to replace the purpose is to better perform page separation, do not display PHP code on the page, the PHP variable in the controller to replace, as you say, the registration page does not use PHP variable, Do you write a HTML file directly when the template is written in JavaScript verification is not finished? Static registration page you can Baidu under.
The role of smarty you do not understand, there is no PHP variable is not replaced at all.
I need a smarty to write the registration code, but I will not use samarty, so want an example, refer to learning, in the online look at the introduction of what, I did not succeed, feel no samarty shadow, so I hope the great God to give a
Can't wait on the line?
Write your hair up and let a person see for you.
Smarty is the program template separation is no hard
It is recommended to take a look at Php+smarty configuration installation.
Write yourself a smarty custom function, according to the specification into the plug-in directory is ok Bai .... For example, the function name is a few arguments behind login
Smarty scalability is very good, so the system function is not much, you need what function, you can define yourself, the specification is quite simple,
For example, smarty_function_ a custom function name, and then write the file name in this way, and then put it in the plugin directory.
Smarty's role is not just a regular substitution of interface separation, caching technology is the key, but this is just filemtime and CRC32 and so on the checksum
So the key to Smarty is to learn how php,,php is achieved, Smarty is how to do
======================sql========================
CREATE TABLE ' user ' (
' user_id ' int (5) not NULL auto_increment,
' user_name ' varchar (not NULL),
' Password ' varchar (not NULL),
PRIMARY KEY (' user_id ')
) Engine=myisam auto_increment=2 DEFAULT Charset=utf8
========================db.php=====================
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->pass Word) or Die ("Database connection failed!"); 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; The 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 class =====================================
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================================
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 "User registration succeeded!". "
"; } else {echo "User already exists!". "
"; }} 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 "user does not exist!". "
"; } else {if ($user _arr[0][' user_name ') = = $user _name && $user _arr[0][' password '] = = $password) { echo "Login successful!"; /*** * Then is the record session, jump to the login successful page * The user name using smarty commonly used assign variable method, on the successful registration of the page out, */} }} 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============== <title>User Registration</title>
==============login.html========================= <title>User Login</title>
ElseIf (isset ($_request[' act ')) && $_request[' act '] = = ' Login_page ') { $smarty->assign ("title", "User Login" ); $smarty->display (' login.html ');} ElseIf (isset ($_request[' act ')) && $_request[' act '] = = ' Register_page ') { $smarty->assign ("title", " User registration "); $smarty->display (' register.html ');} else { $smarty->assign ("title", "User Registration"); $smarty->display (' register.html ');} {$title}
Your user class is that file in Riga, and your last piece of code is added there, can this work?
Who can tell me, and give points?
Your user class is that file in Riga, and your last piece of code is added there, can this work?
This last paragraph is an example of a assign function.
Smarty There's nothing difficult, there's more headaches.
Smarty There's nothing difficult, there's more headaches.
The principle of the template is most of the same is to find the replacement, and then need to PHP array and string processing knowledge, learned the two can do function, PHP is so easy to get started
You're not going to use it, but it's for you.
Pro, can use, this is I finished after debugging verified