w3resource

PHP: sha1() function

Description

The sha1() function is used to calculate the sha1 hash of a string.

Version:

(PHP 4 and above)

Syntax:

sha1(string1, raw_output)

Parameter:

Name Description Required /
Optional
Type
string1 The input string. Required String
raw_output If TRUE sets raw 20 characters binary format. If FALSE (default) sets raw 40 character hex number format. Optional Boolean

Return value:

Returns the sha1 hash as a string.

Value Type: String.

Example:

<?php
$str = 'Good Morning';
echo sha1($str).'<br>';
echo sha1($str,TRUE).'<br>';
?>

Output:

06e336231466d0b0573a05cbca7813444afb5b29
ã6#fаW:ËÊxDJû[)

View the example in the browser

See also

PHP Function Reference

Previous: sha1_file
Next: similar_text



PHP: Tips of the Day

Get the full URL in PHP

Have a look at $_SERVER['REQUEST_URI'], i.e.

Example:

$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

(Note that the double quoted string syntax is perfectly correct)

If you want to support both HTTP and HTTPS, you can use

$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

Editor's note: using this code has security implications. The client can set HTTP_HOST and REQUEST_URI to any arbitrary value it wants.

Ref : https://bit.ly/2ZYItNJ