Super Array
$ _ Cookie $ _ SessionSuper array strictly case sensitive
$ _ COOKIE: During a temporary session, each browser will have this cookie temporarily cached.
$ _ Session: temporary session
The cookie is stored in the local data unsafe. When the time reaches, it will automatically clear the time period. No cached data in the browser will still exist.
Time () + 3600 1 hour time () + 3600*24 1 day time
Setcookie ("tag name", "storage value", Cache Time)
Used for product order or temporary storage
Tag Name: Custom (keyword, Chinese cannot be named)
// Setcookie ("username", "xiaozhu", time () + 3600 );
Setcookie ("username", "", ""); // clear the cookie Cache
Tag Name (case sensitive)
Session is the data security stored on the server.
Set session
Session_start () Start sessionSession_start () is written in the program header ☆
Set session $ _ session ["tag name"] = "stored value ";
Tag Name (case sensitive)
Session is used by individual users. When the browser is closed, the session is cleared (the session is closed). If a browser is re-opened, it is equivalent to re-enabling the session.
// $ _ Session ["username"] = "user ";
// Print_r ($ _ session ["username"]);
Unset ($ _ session ["username"]); // clear a value (or variable)
Session_destroy (); // clear all sessions that have been created
Verification code verification MD5 (encrypted value) MD5 Encryption
Session_start ();
/*
Match the submitted data and verification code of the form.
1: Verification Code painting
2: Form
3: load the verification code in the form
4: Random verification code
5: match the verification code
*/
If (! Empty ($ _ post ))
{
If ($ _ session ['code']! = MD5 (strtolower ($ _ post ['code'])
{
Die ("the verification code you entered is incorrect. re-enter ");
} Else
{
Echo ("<SCRIPT> alert ('verified successfully'); </SCRIPT> ");
}
}
Include ("login.html"); // load view (view separation)
Database: MySQL (PhP Java) sqlserver (C #, Asp.net)
Server installed:
Phpstudy: Default User Name of the software database: Root Password: Root phpMyAdmin built-in Database
Wampserver default username: Password: phpMyAdmin built-in Database
Install software management database integration install navicat_for_mysql
(1): Integrated Installation of navicat_for_mysql
(Link name) Connection Pool (custom name)
Host Name: localhost or 127.0.0.1
Default database port: 3306
Database username: Root
Database Password: Root
Link successful
New Database Name:
Database Name: Custom (naming Rules) (do not start with a keyword or number)
Set Character Set: UTF-8
Set the sorting rule: utf8_general_ci
Create a new table (the ID field must be set as a key, indicating that it is a unique primary key)
Name (field)
Id field (unique)
Data Type
INT (integer)
Keywords in the database are case insensitive
Table names are case-insensitive (but names cannot be repeated)
Username data type: varchar char (string type)
Database: add, delete, modify, and query four statements
Select: Query *: All from: to admin: Table Name
Select * from Admin to admin to query all information
Where: Filter (subquery)
Select * from Admin where id = 2 to query ID = 2 in the admin table
Manual Installation
MySQL Note:/* Comment */
Query statement
// Query a single row statement
Select * from Admin where id = 1
// Query data with an ID greater than 1
Select * from Admin where ID> 1
// Query username = "user" (The table name and field name are marked)
Select * From 'admin' where 'username' = "user"
// Query username = "admin" or ID> 1 (if one of the conditions is met)
// Or | or (if one of the conditions is met, an English word is recommended)
Select * From 'admin' where 'username' = "afasfdas" or ID> 1
// Query username = "user" and must meet Password = "789" (both must meet)
// And & (both must be met. We recommend that you use English words)
Select * From 'admin' where 'username' = "user" & 'Password' = "789"
// Do all the dataReverse output
// Order by: sort the order by field. DESC
// Desc: Descending ASC: ascending (default)
Select * From 'admin' order by ID DESC
// Query all users that contain
// Like fuzzy query like "% query containing content % ";
Select * From 'admin' where username like "% A % ";
// Query the characters starting with a letter in all users
Select * From 'admin' where username like "U % ";
// Query the characters ending with letters in all users
// Select * From 'admin' where username like "% u ";
// Query the first two data records
// Limit number. query a fixed number (limit );
Select * From 'admin' limit 0, 3
Records in the statistical table
Count (*): queries statistics.
Select count (*) from 'admin'
// The field in which you want to get the alias as follows the as keyword to get the name as (can be omitted)
Select count (*) as num from 'admin'
Modify statementModify a single row statement
Modify the statement 'username' = "ABCD" id = 2
// Update Modification
Update 'table name' set' field name' = "value" where id = 2
Update 'admin' set 'username' = "ABCD" where id = 2
Add statementAdd a statement
// Insert
(1)
Insert into 'table name' values ("value 1", "value 2", "value 3 ");
Insert into 'admin' values ("", "aaaa", "123456 ");
(2)
Insert into 'table name' ('field 1', 'field 2', 'field 3') value ("value 1", "value 2", "value 3 ")
Insert into 'admin' ('id', 'username', 'Password') value ("", "wwww", "3456 ")
Delete statementDelete a statement
Delete from 'admin' where id = 8
Delete from 'admin' delete all data in the table
Link Database
Header ("Content-Type: text/html; charset = UTF-8 ");
Session_start (); // start the session
If (! Empty ($ _ post ))
{
// (1): Link to the database (2 link mode) (1) MySQL (2) mysqli
// Mysql_connect ("Host Name", "User Name", "password") link pool
Mysql_connect ("127.0.0.1", "root", "root") or die ("link failure ");
Mysql_select_db ("xiexie"); // select the database name for the operation
Mysql_query ("names set utf8"); // sets the character set encoding format.
$ Username = $ _ post ['username']; // obtain the username entered in the text box.
$ Password = $ _ post ['Password']; // obtain the password entered in the text box.
$ SQL = "select * From 'admin' where 'username' = '{$ username}' and 'Password' = '{$ password}'"; // operate SQL statements
$ Res = mysql_query ($ SQL); // execute an SQL statement
$ ROW = mysql_fetch_assoc ($ res); // The data returned by a result set is an array.
// Verify the verification code
If ($ _ session ['code']! = MD5 (strtolower ($ _ post ['code'])
{
Die ("Incorrect verification code ");
} Else if ($ row ['username'] = "" and $ row ['Password'] = ""){
Die ("account password cannot be blank ");
} Else
// Verify the account password
If ($ row ['username'] = $ username and $ row ['Password'] = $ password)
{
Header ("Location: http: // localhost/11.1/11.1b.php"); // jump to the page
} Else {
Die ("enter the correct account password ");
}
}
Include ("03.html"); // view Loading
Example
11.1 aphp:
10.312php:
03. html:
11.1 Essays