From 3b059adcf447647d4e958d3029982543ede74246 Mon Sep 17 00:00:00 2001 From: Kamran Zafar Date: Mon, 9 Sep 2024 00:48:30 +0500 Subject: [PATCH] feat: "used sessions for security" --- Branches.php | 15 ++++++ Companies.php | 13 ++++++ CompanyInfo.php | 21 ++++++--- box.php | 14 ++++++ boxDelete.php | 16 +++++++ branchDelete.php | 16 +++++++ branchUpdate.php | 14 ++++++ create.php | 16 +++++++ createBox.php | 15 ++++++ createBranch.php | 14 ++++++ createitem.php | 17 +++++++ delete.php | 16 +++++++ index.php | 14 +++++- itemDelete.php | 16 +++++++ itemUpdate.php | 15 ++++++ logout.php | 12 +++++ pages-login.php | 117 ++++++++++++++++++++++++----------------------- showItems.php | 14 ++++++ update.php | 18 ++++++++ 19 files changed, 328 insertions(+), 65 deletions(-) diff --git a/Branches.php b/Branches.php index 0363a2e..bd13946 100644 --- a/Branches.php +++ b/Branches.php @@ -1,4 +1,19 @@ diff --git a/pages-login.php b/pages-login.php index 3f3fb62..51d0d1f 100644 --- a/pages-login.php +++ b/pages-login.php @@ -1,73 +1,74 @@ query("SELECT * FROM register WHERE email='$email' AND password='$password'"); - if(mysqli_num_rows($result) > 0){ - if($password == $row["password"]){ - $_SESSION["login"]=true; - $_SESSION["id"]= $row["id"]; - header("Location: index.php"); - } - else{ - echo ""; + // If a match is found, set the session + if ($result->num_rows > 0) { + $_SESSION['email'] = $email; // Set session variable + header("Location: index.php"); // Redirect to the dashboard or home page + } else { + echo "Invalid login!"; } } -else{ - echo ""; -} -} -// define variables and set to empty values -$email = $password= ""; +// require 'db.php'; -if ($_SERVER["REQUEST_METHOD"] == "POST") { - $email = test_input($_POST["email"]); - $password = test_input($_POST["password"]); -} -function test_input($data) { - $data = trim($data); - $data = stripslashes($data); - $data = htmlspecialchars($data); - return $data; -} +// if(isset($_POST["submit"])){ +// $email= mysqli_real_escape_string($conn, $_POST["email"]); +// $password=mysqli_real_escape_string($conn, $_POST["password"]); + +// $result = mysqli_query($conn, "SELECT * FROM register WHERE email = '$email' AND password='$password'"); + +// $row= mysqli_fetch_assoc($result); + +// if(mysqli_num_rows($result) > 0){ +// if($password == $row["password"]){ +// $_SESSION["login"]=true; +// $_SESSION["id"]= $row["id"]; +// header("Location: index.php"); +// } +// else{ +// echo ""; +// } +// } +// else{ +// echo ""; +// } +// } + +// // define variables and set to empty values +// $email = $password= ""; + +// if ($_SERVER["REQUEST_METHOD"] == "POST") { +// $email = test_input($_POST["email"]); +// $password = test_input($_POST["password"]); +// } + +// function test_input($data) { +// $data = trim($data); +// $data = stripslashes($data); +// $data = htmlspecialchars($data); +// return $data; +// } +// //new code +// + + @@ -147,7 +148,7 @@ function test_input($data) {

Enter your email & password

-
"> +
diff --git a/showItems.php b/showItems.php index 490f423..cf4ff62 100644 --- a/showItems.php +++ b/showItems.php @@ -1,5 +1,19 @@ +