(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