create a hash from string sha1 in php

To create a hash from a string using the SHA1 algorithm in PHP, you can use the hash() function with the "sha1" algorithm identifier. Here's an example:

main.php
$string = "Hello world!";
$hash = hash("sha1", $string);
echo $hash; // Output: 2ef7bde608ce5404e97d5f042f95f89f1c232871
121 chars
4 lines

In the example above, we first define a string $string that we want to hash. We then call the hash() function with the algorithm identifier "sha1" and pass in the string to be hashed as the second argument. The resulting hash is stored in the variable $hash and then printed out using echo.

It's important to note that the SHA1 algorithm is not recommended for cryptographic purposes anymore, as it's considered vulnerable to collision attacks. Instead, you should consider using one of the newer, more secure algorithms available in PHP's hash() function, such as SHA256 or SHA512.

gistlibby LogSnag