標籤:header boolean 服務 演算法 失敗 echo 響應 name family
密碼加密與驗證
password_hash — 建立密碼的雜湊(hash)
string password_hash ( string $password , integer $algo [, array $options ] )
當前支援的演算法($algo的參數):1. PASSWORD_DEFAULT - 使用 bcrypt 演算法 (PHP 5.5.0 預設)。 注意,該常量會隨著 PHP 加入更新更高強度的演算法而改變。 所以,使用此常量產生結果的長度將在未來有變化。 因此,資料庫裡儲存結果的列可超過60個字元(最好是255個字元)。2. PASSWORD_BCRYPT - 使用 CRYPT_BLOWFISH 演算法建立雜湊。 這會產生相容使用 "$2y$" 的 crypt()。 結果將會是 60 個字元的字串, 或者在失敗時返回 FALSE。
password_verify — 驗證密碼是否和雜湊匹配
boolean password_verify ( string $password , string $hash )
樣本:
$password = "123456";//擷取加密後的字串$hash = password_hash($password,PASSWORD_DEFAULT);//驗證密碼$input = "123456";if(password_verify($input,$hash)) echo "密碼正確";else echo "密碼錯誤";
get_headers
取得伺服器響應一個 HTTP 要求所發送的所有標題。
array get_headers ( string $url [, int $format = 0 ] )
參數:
url - 目標 URL。
format - 如果將可選的 format 參數設為 1,則 get_headers() 會解析相應的資訊並設定數組的鍵名。
bccomp
比較兩個任意精度的數字,用於高精度浮點數比較。
int bccomp ( string $left_operand , string $right_operand [, int $scale = int ] )
參數:$scale的作用是設定比較到小數點第幾位為止。
傳回值:
如果兩個數左邊的數left_operand比較右邊的數right_operand相等返回0,
左邊的數left_operand比較右邊的數right_operand大返回1,
左邊的數left_operand比較右邊的數right_operand小返回-1.
php 函數小技巧(一)