title: Keep a user logged in using cookies
body: <p>I have the following code to login:</p>
  
  <pre><code>$query_login = mysql_query("SELECT * FROM users WHERE
    username='".mysql_escape_string($_POST['username'])."' AND
    password='".mysql_escape_string($_POST['password'])."'");
  
  if(mysql_num_rows($query_login)) { 
    $_SESSION['login'] = $_POST['username'];
    header('Location:account.php');
  }   
  </code></pre>
  
  <p>This is only valid for the life of a session. When a user closes his/her browser the session is gone and the user needs to login again.</p>
  
  <p>How do I securely persist sessions using cookies?</p>
  
  <p>I'm concerned that inserting usernames and passwords into cookies is unsafe.</p>