Began to refresh knowledge of php. Looking at the video tutorials on http://www.youtube.com/playlist?list=PLYZm5HGThGRBZ3ym2Ek0h4jQvYAxuPLBe I learned that using sessions to register and authorize users, when they closed the browser and opened it, the fact of logging in to the user account was lost again, so these tutorials said That cookies must be used (since they are stored on the user's hard disk). After reviewing the video tutorials at http://www.youtube.com/watch?v=qFxUApU6104&list=plnxplpxphphhhtThrbb3322kkhhhhhhhhhhtgrbz3ym2Ek0h4jQvYAxuPLBe , http://www.youtube.com/watch?v=ASdD2gasVsA&list=PLYZm5HGTHGRPhp2p4xwpxhpbhhhhhhhhhhh , ? v = Nyk60llAcMc & list = PLYZm5HGThGRBZ3ym2Ek0h4jQvYAxuPLBe , http://www.youtube.com/watch?v=usmj-iQGkII&list=PLYZm5HGThGRBZ3ym2Ek0h4jQvYAppn our name our name our name which name isplpl5HGTHGRBZ35GGGR2GGGGR I thought, but it was not possible to achieve the fixation of the entrance to the account when closing and opening the browser. Help write, using cookies, given that there may be several for one user in case a person for some reason decided to create several accounts for one site, registration and authorization with saving the login to the site. I give the code

<?php $connect = mysql_connect('localhost', 'root', '') or die(mysql_error()); mysql_select_db('tutorials'); if (isset($_POST['submit'])){ $username = $_POST['username']; $login = $_POST['login']; $password = $_POST['password']; $r_password = $_POST['r_password']; if ($password == $r_password){ $password = md5($password); $query = mysql_query("INSERT INTO users VALUES ('', '$username', '$login', '$password')"); //setcookie($login, $password, time() + 3600*24*7, "/"); } else { die('Passwords not match'); } } if (isset($_POST['enter'])){ //echo "OK"; $e_login = $_POST['e_login']; $e_password = md5($_POST['e_password']); $query = mysql_query("SELECT * FROM users WHERE login='$e_login'"); $user_data = mysql_fetch_array($query); if ($user_data['password'] == $e_password) { setcookie($e_login, $e_password, time() + 3600*24*7, "/"); echo '<form method="post" action="register.php"> <input type="text" name="username" placeholder="| Username" required /><br> <input type="text" name="login" placeholder="| Login" required /><br> <input type="password" name="password" placeholder="| Password" required /><br> <input type="password" name="r_password" placeholder="| Repeat password" required /><br> <input type="submit" name="submit" value="Register" /><br> </form>'; echo 'You have already logged in<br> <form method="post" action="register.php"> <input type="submit" name="logout" value="Logout" /> </form>'; } else { echo "Wrong password or login"; } } else { setcookie($e_login, $e_password, time() - 3600*24*7, "/"); echo '<form method="post" action="register.php"> <input type="text" name="username" placeholder="| Username" required /><br> <input type="text" name="login" placeholder="| Login" required /><br> <input type="password" name="password" placeholder="| Password" required /><br> <input type="password" name="r_password" placeholder="| Repeat password" required /><br> <input type="submit" name="submit" value="Register" /><br> </form>'; echo '<form method="post" action="register.php"> <input type="text" name="e_login" placeholder="| Entered login" required /><br> <input type="password" name="e_password" placeholder="| Entered password" required /><br> <input type="submit" name="enter" value="Enter" /><br> </form>'; } ?> 

    2 answers 2

    Somehow it is not clear you have everything. After all, you will save the cookie so that a person can exit the browser, enter - and he is already logged in. But you want to be able to save a few cookies. I do not know why you had this desire, but explain to me how the site will understand which of these cookies to choose to verify the authorization of a person? You cannot assign several different options to a single cookie name - you can only overwrite it. But you can create several different cookies - but how will you check them, I do not understand. Tell your users who want to create multiple accounts and be logged in to all of them in the browser right away - that this is impossible.

      Read, I think the issue will be resolved:

      1. Secure PHP authorization method
      2. Authorization on sites on PHP. Pro cookie in simple language.