I can not understand why the cookie is not displayed, in the browser in the page there is a cookie, and with very correct content (pass), but

var_dump($_COOKIE["pass"]); 

Does NULL always show me?

 if ($user->createUser()){ ob_start(); setcookie('email',$user->email,time()+14400,'/'); setcookie('pass','',time()-86400,'/'); $form = $success; } else $form = $regform; break; case "goodluck": /* Проверка соответсвия пароля */ if ($user->checkPass($_COOKIE[email],$_POST["pass"])){ ob_start(); // установка куки пасс setcookie('pass',$_POST["pass"],time()+86400,'/'); var_dump("cookie[pass]: ",$_COOKIE["pass"],"<br /><pre>"); print_r($_COOKIE); echo "</pre>"; 
  • one
    Password in cookies? It is undesirable to store even password hashes, not to mention the passwords themselves ... - evgeniy
  • Yes, he got excited, did not do it. - Smash

1 answer 1

Well, there may be several options:

1) When you created a cookie, you could create it as "Pass", and try to read from the array as "pass". Register matters!

2) You did not refresh the page after you created the cookie. The $_COOKIE not updated dynamically, like any other PHP variables.

3) The "var_dump ()" function returns information about the variable. Try simply outputting the variable to the browser or debug output the entire array with the print_r() function. Then see if the variable is present in the array at all.

  • in print_r ($ _ COOKIE) for some reason, it is absent, although I can see it in the browser. - Smash
  • I will add code, maybe the picture will be more clearly visible, though ... - Smash
  • So PHP does not load it into an array of cookies. This may be because in the settings (configuration file) of your web server (most likely it is Apache), the cookie cookie flag is disabled. Uncomment this line. - AseN
  • And, now it became clear. I also recently had a similar problem! Try to create a pass cookie not like this: --- setcookie ('pass', '', time () - 86400, '/'); --- well: --- setcookie ('pass', 'none', time () - 86400, '/'); --- Instead of "none" any value longer than 1 character can be desired. It helped me. After all, the cookie "email" is read? - AseN
  • I don’t have a single line about cookies in Apache, I try [cookie] search, there are no matches, but the email clearly shows. - Smash