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?
Register.php :
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 . "<br>" . mysqli_error($conn);
}
}
?>
login.php :
<?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>0){
$_SESSION['username']=$username;
$_SESSION['loggedIn'] = true;
echo "<script>window.open('index.php','_self')</script>";
}
else {
echo "<script>alert('username or password is not correct, try again!')</script>";
}
}
?>