
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
sha1() function in PHP
The sha1() function in PHP is used to calculate the sha1 hash of a string. Let us first see what is SHA-1 −
The US Secure Hash Algorithm 1 − "SHA-1 produces a 160-bit output called a message digest. The message digest can then, for example, be input to a signature algorithm which generates or verifies the signature for the message. Signing the message digest rather than the message often improves the efficiency of the process because the message digest is usually much smaller in size than the message. The same hash algorithm must be used by the verifier of a digital signature as was used by the creator of the digital signature."
-- Ref − RFC 3174
Syntax
sha1(str, raw)
Parameters
str − Specify the string. Required.
raw − A boolean value that specifies hex or binary output format. Optional.
TRUE − Raw 20 character binary format
FALSE − 40 character hex number
Return
The sha1() function returns the calculated SHA-1 hash on success, or FALSE on failure.
Example
The following is an example −
<?php $s = "Welcome"; echo sha1($s); ?>
Output
ca4f9dcf204e2037bfe5884867bead98bd9cbaf8
Example
The following is an example −
<?php $s = "Welcome!"; echo sha1($s); if (sha1($s) == "ca4f9dcf204e2037bfe5884867bead98bd9cbaf8") { echo "<br>Hello Welcome!"; exit; } ?>
Output
e52e5e6cd50ef4de30d8a4fafbbfab41180cc200
- Related Articles
- Difference Between MD5 and SHA1
- filter_has_var() function in PHP
- filter_id() function in PHP
- filter_input() function in PHP
- filter_input_array() function in PHP
- filter_list() function in PHP
- filter_var_array() function in PHP
- filter_var() function in PHP
- constant() function in PHP
- define() function in PHP
- defined() function in PHP
- die() function in PHP
- eval() function in PHP
- exit() function in PHP
- get_browser() function in PHP
