php 函數小技巧(一)

來源:互聯網
上載者:User

標籤: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 函數小技巧(一)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.