title: php change session to cookie
body: <p>Thank you for reading. I have successfully made php file that does sign up and sign in part. But, I need to change SESSION to COOKIE. Just replacing SESSION to COOKIE doesn't seem to be working. How do I change SESSION to COOKIE and make the function works exactly the same as SESSION?</p>
  
  <p>Register.php :</p>
  
  <pre><code>include 'config.php';
  
  if(isset($_SESSION['username'])!="")
  {
    header("location: welcome.php");
  }
  
  if(isset($_POST['submit']))
  {
      $sql = "INSERT INTO user (username, password) VALUES ('".$_POST["username"]."','".$_POST["password"]."')";
      if (mysqli_query($con, $sql)) 
      {
      $_SESSION['username'] = $_POST["username"];
      header("location: login.php");
      } 
      else
      {
        echo "Error: " . $sql . "&lt;br&gt;" . mysqli_error($conn);
      }
  }
  
  ?&gt;
  </code></pre>
  
  <p>login.php :</p>
  
  <pre><code>&lt;?php
  include("config.php");
  session_start();
  
  if(isset($_SESSION['username'])!="")
  {
    header("location: welcome.php");
  }
  
  if (mysqli_connect_errno())
  {
     echo "MySQLi Connection was not established: " . mysqli_connect_error();
  }
  
  if(isset($_POST['login']))
  {
     $username = mysqli_real_escape_string($con,$_POST['username']);
     $password = mysqli_real_escape_string($con,$_POST['password']);
  
     $sel_user = "SELECT * FROM user WHERE username='$username' AND password='$password'";
     $run_user = mysqli_query($con, $sel_user);
  
     $check_user = mysqli_num_rows($run_user);
  
     if($check_user&gt;0){
        $_SESSION['username']=$username;
        $_SESSION['loggedIn'] = true;
        echo "&lt;script&gt;window.open('index.php','_self')&lt;/script&gt;";
     }
     else {
        echo "&lt;script&gt;alert('username or password is not correct, try again!')&lt;/script&gt;";
     }
  
  }
  
  ?&gt;
  </code></pre>