Good day.

We go to the site under the login and password, then close the browser. Open the browser and the site again - you do not need to log in. It is clear that the username and password are remembered by the browser and recorded somewhere.

  1. How to call the above? (for further googling)
  2. Can anyone suggest or give an example of the simplest memorization of a username and password by a site? I am able to write the registration itself, so the final touch remains.

    4 answers 4

    All about cookies and more

    • read. tried on a real hosting. all according to the instructions. the result is only errors. Of course, I can write that in error, but what's the point? (Warning: Cannot modify header information - headers already sent by (output started at ... index.php: 4) in ... index.php) can you explain about cookies like something else? the form on the site, 2 textboxes, 1 button (authorization), login / pass is in the database ... then tell me? - frank
    • @frank - are you friends with manuals? according to the answers if judged so you wait when they write you to make it work. In most cases, they will write here which way to go, but they will not always write the code. - Artem
    • the error was in my actions. did not understand a little. - frank

    The browser does not remember the username / password and session data, which is recorded in the cookie. Here you have a topic for further googling.

      The default session expiration time ends after the browser has been closed, you can extend this time in seconds

      session_set_cookie_params(10800); 
      • Yes you can, only better 60 * 60 * 24 = 86400 ie session_set_cookie_params (86400); - Node_pro
       $is_logged=false; if(isset($do) && $do=="do_login"){ if(isset($login) && isset($password)){ $password=@md5($password); $db->Query("SELECT * FROM `users` WHERE login='$login' and pass='$password'"); if($db->RowCount()){ $row=$db->Row(); setcookie("user_id",$row->id,time()+28800); setcookie("user_password",$password,time()+28800); @session_register("user_id"); @session_register("user_password"); $_SESSION["user_id"]=$row->id; $_SESSION["user_password"]=$password; $is_logged=true; } } }elseif(intval($_SESSION["user_id"]) > 0 && $_SESSION["user_password"]){ $db->Query("SELECT * FROM `users` WHERE id=".intval($_SESSION["user_id"])); $row=$db->Row(); if($_SESSION["user_password"]==$row->pass){ $is_logged=true; }else{ $is_logged=false; } }elseif(intval($_COOKIE["user_id"] > 0)){ $db->Query("SELECT * FROM `users` WHERE id=".intval($_COOKIE["user_id"])); $row=$db->Row(); if($_COOKIE["user_password"]==$row->pass){ $is_logged=true; @session_register("user_id"); @session_register("user_password"); $_SESSION['user_id']=$row->id; $_SESSION['user_password']=$_COOKIE["user_password"]; }else{ $is_logged=false; } } if(!$is_logged){ setcookie("user_id", "", 0); setcookie("user_password", "", 0); $_SESSION["user_id"]=0; $_SESSION["user_password"]=""; $smarty->display("sitelogin.tpl"); } 

      Here is one of the solutions ... By the way, check out the security level.

      • interesting solution. thanks - frank