title: Cookies Remember me issue PHP
body: <p>I am at an absolute pickle.
  I am wanting to create a remember me cookie. Following guides on the net, I am assuming I need to add: </p>
  
  <pre><code>if($_POST['remember']){
      setcookie('remember_me', $_POST['username'], $year);
  }
  elseif(!$_POST['remember']){
      if(isset($_COOKIE['remember_me'])){
          $past = time() - 100;
          setcookie(remember_me, gone, $past);
      }
  }
  
  $year = time() + 31536000;
  setcookie('remember_me', $_POST['username'], $year);
  </code></pre>
  
  <p>to my authentication.php file to set the if statement and create the cookie.</p>
  
  <p>and then setting the value of the username to <code>&lt;?php echo $_COOKIE['remember_me']; ?&gt;</code></p>
  
  <p>which I have done:</p>
  
  <pre><code>&lt;form action="../controller/authentication.php" method="post"&gt;
         &lt;div class="form-group"&gt;
           &lt;label&gt;Username&lt;/label&gt;
          &lt;input class="form-control" placeholder="Username" name="username" type="text" value="&lt;?php echo $_COOKIE['remember_me']; ?&gt;"&gt;&gt;
  
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
        &lt;label&gt;Password&lt;/label&gt;
        &lt;input class="form-control" placeholder="Password" name="password" type="password" value=""&gt;
      &lt;/div&gt;
      &lt;div class="checkbox"&gt;
          &lt;label&gt;
            &lt;input name="remember" id="remember" type="checkbox" value="1"&gt;Remember Me
          &lt;/label&gt; &lt;br&gt;
          &lt;small id="signup" class="form-text text-muted"&gt;Don't have an account yet? &lt;a href='signup.php'&gt;Sign Up&lt;/a&gt;.&lt;/small&gt;
        &lt;/div&gt;
               &lt;button type="submit" class="btn btn-primary"&gt;Login&lt;/button&gt;
       &lt;/form&gt;
  </code></pre>
  
  <p>Now the issue is saying that
   <code>Notice: Undefined index: username in C:\Users\Bob\Desktop\Xammp\htdocs\Shopping_List\view\index.php on line 7</code> so it doesn't seem to be reading my cookie statement within the form correctly and I don't know if the cookie statement is set up correctly...</p>
  
  <p>Not sure if this helps but I will show you my authentication file as well</p>
  
  <pre><code>    &lt;?php
  //start session management
      session_start();
  //connect to the database
  require('../model/connection.php');
  //retrieve the functions
  require('../model/functions_users.php');
  
  //retrieve the username and password entered into the form
  $username = $_POST['username'];
  $password = $_POST['password'];
  
  
  
  if($_POST['remember']){
      setcookie('remember_me', $_POST['username'], $year);
  }
  elseif(!$_POST['remember']){
      if(isset($_COOKIE['remember_me'])){
          $past = time() - 100;
          setcookie(remember_me, gone, $past);
      }
  }
  
  $year = time() + 31536000;
  setcookie('remember_me', $_POST['username'], $year);
  
  //call the retrieve_salt() function
  $result = retrieve_salt($username);
  
  //retrieve the random salt from the database
  $salt = $result['salt'];
  //generate the hashed password with the salt value
  $password = hash('sha256', $password.$salt);
  
  //call the login() function
  $count = login($username, $password);
  
  //if there is one matching record
  if($count == 1)
  {
      //start the user session to allow authorised access to secured web pages
      $_SESSION['user'] = $user;
      //if login is successful, create a success message to display on the products page
      $_SESSION['success'] = 'Hello ' . $username . '. Have a great day!';
  
  
      //redirect to products.php
      header('location:../view/products.php');
  }
  else
  {
      //if login not successful, create an error message to display on the login page
      $_SESSION['error'] = 'Incorrect username or password. Please try again.';
      //redirect to login.php
      header('location:../view/index.php');
      }
  ?&gt;
  </code></pre>
  
  <p>Any help or tips would be much appreciated.</p>