Php Note 1-php Tutorial

Source: Internet
Author: User
Php note 1. Login verification steps:

1. assign values. use $ _ POST to pass the id and password to the loginProcess. php login verification page.

2. create a database connection $ conn = mysql_connect ($ host, $ username, $ password );

3. select the database mysql_select_db (empmanage );

4. define the SQL statement $ SQL = "select password from admin ";

5. execute the SQL statement and obtain the result $ res = mysql_query ($ SQL, $ conn );

6. compare the password (condition statement)

If ($ row = mysql_fetch_assco ($ res )){

If ($ password = $ row ['password']) {

// The verification is successful and you are redirected to the specified page.

Header ("Location: emp. php ");

Exit ();

} Else {

// If verification fails, return to the login page.

Header ("Location: login. php? Error = 1 ");

Exit ();

}

}

7. release the resource mysql_free_result ($ res );

8. close the connection (automatic) mysql_close ($ conn );

2. several PHP writing principles:

1. release resources from where they are generated

2. close the connection

3. stratified thinking ?????? Very important.

4. a function can return only one result.

3. object-oriented programming, which encapsulates common tool classes.

(For details, refer to the php folder)

IV. cookie knowledge points

1. how to create a cookie?

The setcookie () function is used to set the cookie.

Note: The setcookie () function must be locatedBefore the tag.

Syntax:

Setcookie (name, value, expire, path, domain );

Note:


2. how can I retrieve the Cookie value?

The $ _ COOKIE variable of PHP is used to retrieve the cookie value.

For example, in the following example, we use the isset () function to check whether the cookie has been set:

If (isset ($ _ COOKIE ["user"])

Echo "Welcome". $ _ COOKIE ["user"]. "!
"; // Cookie itself is a super Global array;

Else

Echo "cookie does not exist
";

?>

3. if you enter Chinese characters, the browser will Recode urlencode and can also use urldecode for decoding.

Example:

V. Time zone problems

Q: Why is the date () function used in PHP 8 hours different from the current local time?

Method 1:
Date_default_timezone_set ('prc ');
No return value. Now we can use the date function directly.
$ Time = date (Y. "year". m. "month". d. "day". G. "hour". I. "minute ");

Method 2:

In php. ini, modify date. timezone = to date. timezone = "Asia/Shanghai" (or change to date. timezone = PRC), remove the semicolon, and restart Apache.

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.