sha1
Calculates the SHA-1 hash of a string.
Syntax
sha1(string $string, bool $binary = false): stringParameters
| Parameter | Type | Description |
|---|---|---|
| $string | string | The input string. |
| $binary | bool | Optional. `true` returns 20 raw bytes instead of text. |
Return value
stringA hash of 40 hexadecimal characters.
Examples
The hash of a string:
<?php
echo sha1('hello');Output:
aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434dNotes
SHA-1 is unsuitable for passwords and signatures. Use password_hash() for passwords and hash('sha256', …) for integrity checks.
See also
- md5 — Returns the MD5 hash of a string.
- hash — Returns the hash of a string using a chosen algorithm.
- password_hash — Creates a password hash for storing in a database.
In the tutorial
- Security — The basics of PHP site security — XSS and escaping, SQL injection, password hashing, CSRF tokens and validating input.