crypt(): No salt parameter was specified. You must use a randomly generated salt and a strong hash function to produce a secure hash function [closed]

The salt parameter is optional. However, crypt() creates a weak hash without the salt, and raises an E_NOTICE error without it. Make sure to specify a strong enough salt for better security.

function generate_salt($len = 8) {
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()-=_+';
$l = strlen($chars) - 1;
$str = '';
for ($i = 0; $i<$len; ++$i) {
    $str .= $chars[rand(0, $l)];
}
return $str;

}

$generate_salt = generate_salt($len = 8); $str = "$5$" . $generate_salt . "$"; $c = crypt(uniqid(), $str); echo $c; // $5$ot6wbbf+$wtwWCC8wmE01cNeHGGLMGqkWqiDWyHWfdXQvEOLI7.5

This is correct way to generate salt for crypt function.