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 optionalformat
If 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_operand
Compare the number on the rightright_operand
1 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 ]] )