2016-12-1 Web Project First day

Source: Internet
Author: User
Tags md5 encryption

Today began to learn the knowledge of Web applications, quite excited, learned so long things finally can actually come out with, the main beneficial aspect is to understand some of the features of the Web to achieve the goal and way, although thinking logically good, but the details are still inferior to the experienced people.

The first is the overall structure of the Web, the first user request PHP files, PHP files through certain rules from SQL to call out the data and through the HTML display. In general, HTML is used to display content, PHP is used for operations (the root of Dynamic Web pages), and SQL is used to store the required data.

===============================================================================

Review of HTML Forms

For HTML form labels from (form), the data is submitted to the specified PHP file by the action= "PHP file" with its own property, and the attribute method= ' post ' specifies how the data is submitted (typically with post, at least for the form). In PHP, you can accept HTML-submitted data by using constant $_post.

For elements within a form, specify the part of the data that needs to be submitted by assigning it a name= ' name (named according to the meaning of the data), and value specifies the default value of the commit data (so that it understands better memory), and value is used almost exclusively for single-radio and multiple-select checkboxes. Examples are as follows:

<input type= "Radio" name= "Gender" value= "male" > Male

<input type= "Radio" name= "Gender" value= "female" > Female

<input type= "Radio" name= "Gender" value= "secret" > Secrecy

Radio radio Use the method as above, because radio does not have a certain output value, so each option needs to define its own value values, such as: male =male; female =female; secrecy =secret. And each option commits a value that is defined by value

You also need to set the name value of each option to the same to identify these radio belong to a piece, the HTML will be the name of the same value radio is considered an option column.

When receiving the value passed by radio, it is necessary to set the enum (' Male ', ' female ', ' secret ') in the field properties of SQL to restrict the data being written, although it is not very meaningful, but it can be used as a good identifier.

Multiple options in a form also need to define the same name value to identify multiple multiple selection options for the same column, but multiple selections need to pass more than one value, so the name as a multi-select subscript can only pass a value. Therefore, the value of the multi-select option is implemented by storing the value of the multiple selection in the associative array and passing the array through the name subscript:

<input type= "checkbox" Name= "hobby[]" value= "" >

That is, when you define a name value, you use an array to define it.

(converts an array into a string when stored in SQL [SQL cannot store arrays])

Implode (', ' $ array variable) is used to stitch elements of an array into strings

===========================================================================

About PHP Accepting data

For a form form, the data that is received by $_post is an array, and the subscript of the element is the name value of each definition, and the value of the element is the value of each input or calculation, and the value of radio, such as no value, will be used with values defined by value.

(a variable is generally defined to alone the value of the element in the stored $_post, e.g.: $user _gender=$_post[gender]).

About form data processing:

Empty () Clears the space that the user has typed.

MD5 () is used to encrypt the password, the password is generally stored in the database, MD5 encryption is an irreversible operation, but the same string of characters MD5 code is fixed, so when the user login needs to make a password match, will be the user typed password after the MD5 encryption operation with the MD5 code in the database, To achieve the skill verification password, but also to protect the user's data security.

===============================================================================

Questions about the page

The entire building of the Web generally follows the structure of display and operation, which means that HTML is used for presentation, while the dynamic presentation in HTML is implemented by PHP, and PHP is dedicated to data processing.

In other words, the HTML display should be built after PHP, so HTML should not be directly accessible to the user, but should be a PHP request to access.

Using Apache's Distributed configuration file (httpd-vhosts.conf) to achieve:

<virtualhost *:80>

<Directory>

AllowOverride All

</Directory>

</VirtualHost >

File. htaccess:

Deny from all

After the setup is complete, the HTML corresponding to the virtual station will be able to implement the Access denied function.

===============================================================================

Web Apps

Initializing files

The most common basic code is saved, which is used by every script.

Header ("Content-type:text/html;charset=utf-8");

Define ("Dir_root", str_replace (' \ \ ', '/', _dir_). /’);

Define ("Dir_config", Dir_root. ' config/');

Define ("Dir_con", Dir_root. ' controller/');

Define ("Dir_core", Dir_root. ' core/');

Define ("Dir_model", Dir_root. ' model/');

Define ("Dir_view", Dir_root. ' view/');

Define ("Dir_public", '/public '); The/representing root directory here

Define a path that needs to be repeated multiple times to make it easy to use.

===============================================================================

Connecting to a database

$link = mysql_connect ("localhost:3306", ' Root ', ' Zhouyang ')

mysql_query (' Set names UTF8 ');

mysql_query (' Use library name ');

===============================================================================

PHP usage functions

Trim ()--go to the space.

Empty ()--Determines whether it is empty, returns true if NULL, or returns FALES.

Header ("Refresh: wait number of seconds; url= jump to File")--set page jump.

Strlen ()--Returns the length of the string.

mysql_query ()--Runs the specified command in SQL.

The project is still in the review and repeat setup phase, looking forward to the content after the project.

2016-12-1 Web Project First day

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.