Complete PHP String Reference
The sha1_file() function calculates the SHA-1 hash of a file.
The sha1_file() 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.
| Parameter | Description |
|---|---|
| file | Required. The file to be calculated |
| raw | Optional. Specifies hex or binary output
format:
Note: This parameter was added in PHP 5.0 |
The output of the code above will be:
Store the SHA-1 hash of "test.txt" in a file:
In this example we will test if "test.txt" has been changed (that is if the SHA-1 hash has been changed):
The output of the code above could be:
Complete PHP String Reference
| WEB HOSTING |
|---|
| Best Web Hosting |
| PHP MySQL Hosting |
| Best Hosting Coupons |
| UK Reseller Hosting |
| Cloud Hosting |
| Top Web Hosting |
| $3.98 Unlimited Hosting |
| Premium Website Design |
| WEB BUILDING |
|---|
| XML Editor - Free Trial! |
| FREE Website BUILDER |
| Best Website Templates Top CSS Templates |
| CREATE HTML Websites |
| EASY WEBSITE BUILDER |
| W3SCHOOLS EXAMS |
|---|
|
Get Certified in: HTML, CSS, JavaScript, XML, PHP, and ASP |
| W3SCHOOLS BOOKS |
|---|
|
New Books: HTML, CSS JavaScript, and Ajax |
| STATISTICS |
|---|
|
Browser Statistics Browser OS Browser Display |
| SHARE THIS PAGE |
|---|