Find a login page written by smarty

Source: Internet
Author: User
For a login page written by smarty, you need the code on the login page written by smarty. In addition, you need to set up the required file for the project. baidu search cannot be used, I want to learn about samrty here. thank you first.


Reply to discussion (solution)

Online, etc. you can add qq906988410

What do you mean? The purpose of smarty's replacement is to better execute page separation. The PHP code is not displayed on the page and the PHP variable is replaced in the controller, as you said, the registration page does not use the PHP variable at all. you can directly write an HTML file. when some JAVASCRIPT verification is written in the template, isn't it all done? On the static registration page, you can go to Baidu ..
You have not figured out the role of smarty, and you do not need to replace PHP variables without them.

I need a registered code written with smarty, but I won't use samarty. so I want an example. For more information, see the introduction on the Internet, no samarty shadow.

Why can't I wait online?

Let's take a look at what you wrote.
Smarty is nothing difficult to separate program templates.

We recommend that you check the php + smarty configuration for installation and use.

Write a smarty user-defined function by yourself and put it under the plug-in directory according to the specifications ...... for example The function name is the number of parameters following login.


The scalability of smarty is very good, so there are not many system functions. you can define the functions you need and the specifications are quite simple,
For example, the smarty_function _ user-defined function name is written as the file name, and then put it in the plugin directory.

The role of smarty is not only a regular expression replacement for interface separation, but the cache technology is the key, but it is also a verification of filemtime and crc32.

So the key to smarty is to learn php well, how php is implemented, and how smarty is implemented.

===================================== 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 ================================
 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 ("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;} public function add_data ($ table, $ fields = array (), $ values = array () {$ SQL = "insert ". $ 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-> getOb J ($ SQL) ;}}?> ============================= User. php ======================================
 Compile_check = true; $ smarty-> debugging = false; if (isset ($ _ REQUEST ['AC']) & $ _ REQUEST ['AC'] = '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 successful! "."
";} Else {echo" the user already exists! "."
";}} Elseif (isset ($ _ REQUEST ['AC']) & $ _ REQUEST ['AC'] = '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 "the user does not exist! "."
";} Else {if ($ user_arr [0] ['User _ name'] = $ user_name & $ user_arr [0] ['password'] = $ password) {echo "logon successful! ";/*** Then, record the session and jump to the logon success page. * Use the assign variable method commonly used by smarty to retrieve the username from the successfully registered page, */}}} elseif (isset ($ _ REQUEST ['AC']) & $ _ REQUEST ['AC'] = 'login _ page ') {$ smarty-> display('login.html ');} elseif (isset ($ _ REQUEST ['AC']) & $ _ REQUEST ['AC'] = 'register _ page') {$ smarty-> display('register.html ');} else {$ smarty-> display('register.html ') ;}?> Please refer to the following link for more information: User registration Please refer to the following link for more information: User logon

Elseif (isset ($ _ REQUEST ['AC']) & $ _ REQUEST ['AC'] = 'login _ page ') {$ smarty-> assign ("title", "user logon"); $ smarty-> display('login.html ');} elseif (isset ($ _ REQUEST ['AC']) & $ _ REQUEST ['AC'] = '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 added to the file, and your last code is added to it. can this be run?

Can anyone tell me?

Your user class is added to the file, and your last code is added to it. can this be run?


The last section is an example of the assign function.

Is there no difficulty in smarty? there are too many headaches.

Is there no difficulty in smarty? there are too many headaches.



Most of the template principles are the same: Search and replacement, and then the PHP array and string processing knowledge are required. after learning these two functions, PHP is easy to use.

You can't use this, but you can still share it with me.

Yes, you can use it. this is verified after I finish writing it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.