PHP Basics Review 2018-06-18

Source: Internet
Author: User
Tags change settings php session php basics setcookie

(1) cookie-related

Cookies are often used to identify users. A cookie is a small file that the server leaves on the user's computer. Whenever the same computer requests a page through a browser, it also sends a cookie.

How do I create a cookie?

The Setcookie () function is used to set cookies. Syntax: Setcookie (name, value, expire, path, domain);

Note: When a cookie is sent, the value of the cookie is automatically URL-encoded and automatically decoded upon retrieval (to prevent URL encoding, use Setrawcookie () instead).

How do I retrieve the value of a Cookie?

PHP's $_cookie variable is used to retrieve the value of the COOKIE.

How do I delete cookies?

When you delete a cookie, you should change the expiration date to a past point in time.
Setcookie ("User", "", Time ()-3600);

(2) PHP Sessions

The PHP session variable is used to store information about a user's session or to change settings for a user session. The Session variable holds information that is single-user and can be used by all pages in the application.

Turn on Session:session_start ().

The correct way to store and retrieve session variables is to use PHP $_session variables.

To delete some session data, you can use the unset () or Session_destroy () function.

(3) PHP Filter_var () function

Function: Gets a variable and filters it.

Syntax: Filter_var (variable, filter, options)

example, filtering an email

$field=filter_var ($email,if(Filter_var ($field, filter_validate _email)) {    returnTRUE;} Else {    returnFALSE;}

The second parameter of the function is commonly judged:

Filter_validate_url validates the value as a URL.
Filter_validate_email the value as an e-mail to verify.
Filter_validate_ip the value as an IP address to verify.
Filter_validate_float validates the value with a floating-point number.
Filter_sanitize_email Delete all characters except letters, numbers, and!#$%& ' *+-/=?^_ ' {|} [Email protected] []

PHP Basics Review 2018-06-18

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.