I hash cookies, but it turns out the same hash, although all strings are different.

(string) $server_name = hash("sha512", $_SERVER[SERVER_NAME]); if($server_name != null) { setcookie("domain", $server_name); echo("$server_name"); } (string) $ip = hash("sha512", $_SERVER[REMOTE_ADDR]); if($ip != null) { setcookie("IP", $ip); echo("$ip"); } 

Closed due to the fact that off-topic participants are Visman , andreymal , aleksandr barakin , MihailPw , D-side July 2, 17 at 12:54 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Visman, andreymal, aleksandr barakin, MihailPw, D-side
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • What a terrible algorithm - sha521 ? And why are you hashing $_SERVER[SERVER_NAME] and $_SERVER[REMOTE_ADDR] ? Do you think about their content or who does not guess from the name of the cook? Hash algorithms can be viewed here php.net/manual/ru/function.hash-algos.php - Visman
  • Thank you for finding an error in the sha512 code instead of sha521 - Anton Loginov
  • I do everything according to the philosophy of not storing the ground data on the user's computer in the open form, since the user is always compliant. In general, I hash for security - Anton Loginov
  • one
    You misunderstand this concept. - Visman
  • @AntonLoginov yes, the user will simply change your server / ip hash to any other server / ip hash;) - andreymal

1 answer 1

Stepped, the code given in the question works correctly.