Common PHP functions and tips

Source: Internet
Author: User

Common PHP functions and tips
Password Encryption and Verification

Password_hash-hash used to create a password)

string password_hash ( string $password , integer $algo [, array $options ] )
Currently supported algorithms ($ algo parameter): 1. PASSWORD_DEFAULT-use the bcrypt algorithm (default for PHP 5.5.0 ). Note that this constant will change with the addition of PHP to update more intensive algorithms. Therefore, the length of the result generated using this constant will change in the future. Therefore, the columns storing results in the database can contain more than 60 characters (preferably 255 characters ). 2. PASSWORD_BCRYPT-use the CRYPT_BLOWFISH algorithm to create a hash. This will generate crypt () compatible with "$ 2y $ (). The result will be a string of 60 characters, or FALSE will be returned in case of failure.

Password_verify-verify that the Password Matches the hash

boolean password_verify ( string $password , string $hash )

Example:

$ P = "123456"; // obtain the encrypted string $ hash = password_hash ($ p, PASSWORD_DEFAULT); // verify the password $ input = "123456 "; if (password_verify ($ input, $ hash) {echo "correct password" ;}else {echo "Incorrect password ";}

 

Http_build_query

Generate the request string after URL-encode for the array or object.

 

Parse_url

Parse the URL and return its components.

 

Get_headers

Obtains all the headers sent by the server in response to an HTTP request.

array get_headers ( string $url [, int $format = 0 ] )

Parameters:

url - Target URL.

format - If the optionalformatIf the parameter is set to 1, get_headers () will parse the corresponding information and set the key name of the array.

 

Bccomp

Compares two numbers with any precision for high-precision floating-point comparison.

int bccomp ( string $left_operand , string $right_operand [, int $scale = int ] )

Parameter: $ scale is used to compare the number of decimal places.

Return Value: if the two numbers are equal, 0 is returned, and the number on the left is returned.left_operandCompare the number on the rightright_operand1 is returned; otherwise-1 is returned.

 

Filter_var

Filter a variable using a specific filter for data verification.

mixed filter_var ( mixed $variable [, int $filter = FILTER_DEFAULT [, mixed $options ]] )

 

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.