PHP sha1() Function
Complete PHP String Reference
Definition and Usage
The sha1() function calculates the SHA-1 hash of a string.
The sha1() function uses the US Secure
Hash Algorithm 1.
From RFC 3174 -
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."
This function returns the calculated SHA-1 hash on success, or FALSE on failure.
Syntax
Parameter |
Description |
string |
Required. The string to be calculated |
raw |
Optional. Specify hex or binary output
format:
- TRUE - Raw 20 character binary format
- FALSE - Default. 40 character hex number
Note: This parameter was added in PHP 5.0 |
Example 1
<?php
$str = 'Hello';
echo sha1($str);
?>
|
The output of the code above will be:
f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0
|
Example 2
In this example we will print the result of sha1() and then test it:
<?php
$str = 'Hello';
echo sha1($str);
if (sha1($str) == 'f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0')
{
echo "<br />Hello world!";
exit;
}
?>
|
The output of the code above will be:
f7ff9e8b7bb2e09b70935a5d785e0cc5d9d0abf0
Hello world!
|
Complete PHP String Reference
Make your web applications look like a million bucks
|
|
Most web applications today use boring methods to present data to their viewers using grids or simple HTML tables. FusionCharts induces "life" into the web applications by converting monotonous data into lively charts, gauges & maps.
FusionCharts works with all technologies like ASP, ASP.NET, PHP, ColdFusion, Ruby on Rails, JSP, HTML pages etc.
and connects to any database to render animated & interactive charts. It takes less than 15 minutes and no expertise
whatsoever to build your first chart and just a glance of it to captivate your audience. This fact is endorsed by our
12,000 customers and 150,000 users which include a majority of the Fortune 500 companies.
And yeah, your applications could look like a million bucks by spending just $69.
So go ahead, download your
copy of FusionCharts and start "wow-ing" your customers now!
|
|