Purely academic class, I do not understand why the cookie is not put, in var_dump $ _COOKIE ['login'] gives out NULL.

<?php class Auth { private $login; private $passwd; public function ath() { $this->login = md5('123'); $this->passwd = md5('123'); setcookie("login", $login, time()+3600*24, '/'); setcookie("pass", $passwd, time()+3600*24,'/'); } } /***********************/ $m1 = new Auth(); $m1 -> ath(); ?> 
  • one
    $login and $passwd you do not exist. - Visman

1 answer 1

Empty values ​​- delete cookies, and do not set it. You confused $ this-> login and $ login variables, and also $ this-> passwd and $ passwd

 <?php class Auth { private $login; private $passwd; public function ath() { $this->login = md5('123'); $this->passwd = md5('123'); setcookie("login", $this->login, time()+3600*24, '/'); setcookie("pass", $this->passwd, time()+3600*24,'/'); } } /***********************/ $m1 = new Auth(); $m1 -> ath(); ?> 
  • You are a genius, thank you! I will not get used to OOP! (forgot to use $ this to refer to the corresponding field) - p4sh