title: Implementing Remember me using php
body: <p>I don't know what is going wrong in my code.I have already implemented login and signup using ajax calls. Now, I am trying to implement remember me using cookies in php. My code for that goes like this</p>
  
  <pre><code>&lt;?php require 'database.php';
  session_start();
  if(!empty($_POST["login"])) {
      #$conn = mysqli_connect("localhost", "root", "", "blog_samples");
      $sql = "Select * from login where Username = '" . $_POST["member_name"] . "' and Password = '" . ($_POST["member_password"]) . "'";
      $result = mysqli_query($conn,$sql);
      $user = mysqli_fetch_array($result);
      if($user) {
  
              if(!empty($_POST["remember"])) {
                  setcookie ("member_login",$_POST["member_name"],time()+ (10 * 365 * 24 * 60 * 60));
                  setcookie ("member_password",$_POST["member_password"],time()+ (10 * 365 * 24 * 60 * 60));
              } else {
                  if(isset($_COOKIE["member_login"])) {
                      setcookie ("member_login","");
                  }
                  if(isset($_COOKIE["member_password"])) {
                      setcookie ("member_password","");
                  }
              }
              header("location:private.php");
      }
  }
  ?&gt;  
  
  
  &lt;!DOCTYPE html&gt;
  &lt;html &gt;
  &lt;body&gt;
    &lt;div class="container-fluid"&gt;
   &lt;div class="form-body-login col-md-6 col-xs-6"&gt;
  
     &lt;form class="Login" method="post" action="private.php"&gt;
       &lt;div class="row buttons"&gt;
         &lt;div type="submit" class="col-md-6 col-xs-6 login"&gt;Login&lt;/div&gt;
         &lt;div type="submit" class="col-md-6 col-xs-6 sign_up"&gt;Sign up&lt;/div&gt;
       &lt;/div&gt;
       &lt;/div&gt;
       &lt;div class="login_body"&gt;
         &lt;div class="row user_name"&gt;
           &lt;i class="fa fa-user fa-2x col-md-1 col-xs-1" aria-hidden="true"&gt;&lt;/i&gt;
           &lt;input type="text" class="col-md-10 col-xs-10 username" id="username_login" placeholder="abc@xyz.com" name="member_name" value="&lt;?php if(isset($_COOKIE["member_login"])) { echo $_COOKIE["member_login"]; } ?&gt;" /&gt;
         &lt;/div&gt;
       &lt;div class="row pwd"&gt;
         &lt;i class="fa fa-key fa-2x col-md-1 col-xs-1" aria-hidden="true"&gt;&lt;/i&gt;
       &lt;input type="password" class="col-md-10 col-xs-10 password" id="password_login" placeholder="Password" name="member_password" value="&lt;?php if(isset($_COOKIE["member_password"])) { echo $_COOKIE["member_password"]; } ?&gt;"/&gt;
       &lt;/div&gt;
          &lt;div class="row remember col-md-11 col-xs-11"&gt;
          &lt;label&gt;&lt;input type="checkbox" name="autologin" id="checkbox" name="remember" &lt;?php if(isset($_COOKIE["member_login"])) { ?&gt; checked &lt;?php } ?&gt;/&gt; Remember Me &lt;/label&gt;
          &lt;/div&gt;
          &lt;div class="row col-md-11 col-xs-11"&gt;
            &lt;button type="submit" id="button" name="login"&gt;Login&lt;/button&gt;
          &lt;/div&gt;
       &lt;/div&gt;
       &lt;div class="form-body-signup"&gt;
       &lt;div class="row username_signup"&gt;
       &lt;input type="text" id="username_signup" class="col-md-10" placeholder="Enter user name"/&gt;
       &lt;/div&gt;
         &lt;div class="row password_signup"&gt;
           &lt;input type="password" id="password_signup" class="col-md-10 col-xs-10" placeholder="Enter password here" /&gt;
         &lt;/div&gt;
         &lt;div class="row phone"&gt;
           &lt;input type="text" id="phone" class="col-md-10 col-xs-10" placeholder="enter phone number" /&gt;
         &lt;/div&gt;
  
       &lt;div class="row signup_button"&gt;
         &lt;button type="submit" id="check"&gt;Create New User&lt;/button&gt;
       &lt;/div&gt;
            &lt;/div&gt;
     &lt;/form&gt;
  
  
  &lt;/div&gt;   
    &lt;/div&gt;  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>On login or signup, after doing all the necessary validations, the page directs to private.php. That page looks something like this:</p>
  
  <pre><code>&lt;?php
  echo"Hello";
  session_start();
  #$_SESSION["member_id"] = "";
  session_destroy();
  #header("Location: ./");
  ?&gt;
  </code></pre>
  
  <p>But somehow, the cookies are not getting stored if I check the remember me check box.
  I am doing this for the first time and don't really know what is going wrong here.</p>