Skip to content

Commit

Permalink
feat: "used sessions for security"
Browse files Browse the repository at this point in the history
  • Loading branch information
kamranzafar4343 committed Sep 8, 2024
1 parent b9188b4 commit 3b059ad
Show file tree
Hide file tree
Showing 19 changed files with 328 additions and 65 deletions.
15 changes: 15 additions & 0 deletions Branches.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
<?php
// session_start(); // Start the session
session_start();

session_regenerate_id(true); // This will regenerate the session ID and delete the old one
ini_set('session.cookie_secure', '1'); // Only send cookies over HTTPS
ini_set('session.cookie_httponly', '1'); // Prevent access to cookies via JavaScript (mitigates XSS)
ini_set('session.cookie_samesite', 'Strict'); // Prevent CSRF attacks by restricting cross-site cookie sharing


// Check if the user is logged in
if (!isset($_SESSION['email'])) {
// If not logged in, redirect to login page
header("Location: pages-login.php");
exit();
}

include 'db.php'; // Include the database connection

Expand Down
13 changes: 13 additions & 0 deletions Companies.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
<?php
// session_start(); // Start the session
session_start();

session_regenerate_id(true); // This will regenerate the session ID and delete the old one
ini_set('session.cookie_secure', '1'); // Only send cookies over HTTPS
ini_set('session.cookie_httponly', '1'); // Prevent access to cookies via JavaScript (mitigates XSS)
ini_set('session.cookie_samesite', 'Strict'); // Prevent CSRF attacks by restricting cross-site cookie sharing


// Check if the user is logged in
if (!isset($_SESSION['email'])) {
// If not logged in, redirect to login page
header("Location: pages-login.php");
exit();
}
include 'db.php'; // Include the database connection

// // Check if the user is logged in
Expand Down
21 changes: 15 additions & 6 deletions CompanyInfo.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
<?php
// session_start(); // Start the session
session_start();

session_regenerate_id(true); // This will regenerate the session ID and delete the old one
ini_set('session.cookie_secure', '1'); // Only send cookies over HTTPS
ini_set('session.cookie_httponly', '1'); // Prevent access to cookies via JavaScript (mitigates XSS)
ini_set('session.cookie_samesite', 'Strict'); // Prevent CSRF attacks by restricting cross-site cookie sharing


// Check if the user is logged in
if (!isset($_SESSION['email'])) {
// If not logged in, redirect to login page
header("Location: pages-login.php");
exit();
}

include 'db.php';
// // Check if the user is logged in
// if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
// // User is not logged in, redirect to login page
// header("Location: pages-login.php");
// exit;
// }

$result = [];
$company_data = null;
Expand Down
14 changes: 14 additions & 0 deletions box.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
<?php
// session_start(); // Start the session
session_start();

session_regenerate_id(true); // This will regenerate the session ID and delete the old one
ini_set('session.cookie_secure', '1'); // Only send cookies over HTTPS
ini_set('session.cookie_httponly', '1'); // Prevent access to cookies via JavaScript (mitigates XSS)
ini_set('session.cookie_samesite', 'Strict'); // Prevent CSRF attacks by restricting cross-site cookie sharing


// Check if the user is logged in
if (!isset($_SESSION['email'])) {
// If not logged in, redirect to login page
header("Location: pages-login.php");
exit();
}
include 'db.php'; // Include the database connection

// Fetch box of the company
Expand Down
16 changes: 16 additions & 0 deletions boxDelete.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
<?php
// session_start(); // Start the session
session_start();

session_regenerate_id(true); // This will regenerate the session ID and delete the old one
ini_set('session.cookie_secure', '1'); // Only send cookies over HTTPS
ini_set('session.cookie_httponly', '1'); // Prevent access to cookies via JavaScript (mitigates XSS)
ini_set('session.cookie_samesite', 'Strict'); // Prevent CSRF attacks by restricting cross-site cookie sharing


// Check if the user is logged in
if (!isset($_SESSION['email'])) {
// If not logged in, redirect to login page
header("Location: pages-login.php");
exit();
}

include "db.php";

if (isset($_GET['id'])) {
Expand Down
16 changes: 16 additions & 0 deletions branchDelete.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
<?php
// session_start(); // Start the session
session_start();

session_regenerate_id(true); // This will regenerate the session ID and delete the old one
ini_set('session.cookie_secure', '1'); // Only send cookies over HTTPS
ini_set('session.cookie_httponly', '1'); // Prevent access to cookies via JavaScript (mitigates XSS)
ini_set('session.cookie_samesite', 'Strict'); // Prevent CSRF attacks by restricting cross-site cookie sharing


// Check if the user is logged in
if (!isset($_SESSION['email'])) {
// If not logged in, redirect to login page
header("Location: pages-login.php");
exit();
}

include "db.php";

if (isset($_GET['id'])) {
Expand Down
14 changes: 14 additions & 0 deletions branchUpdate.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
<?php
// session_start(); // Start the session
session_start();

session_regenerate_id(true); // This will regenerate the session ID and delete the old one
ini_set('session.cookie_secure', '1'); // Only send cookies over HTTPS
ini_set('session.cookie_httponly', '1'); // Prevent access to cookies via JavaScript (mitigates XSS)
ini_set('session.cookie_samesite', 'Strict'); // Prevent CSRF attacks by restricting cross-site cookie sharing


// Check if the user is logged in
if (!isset($_SESSION['email'])) {
// If not logged in, redirect to login page
header("Location: pages-login.php");
exit();
}

include "db.php";

Expand Down
16 changes: 16 additions & 0 deletions create.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
<?php
// session_start(); // Start the session
session_start();

session_regenerate_id(true); // This will regenerate the session ID and delete the old one
ini_set('session.cookie_secure', '1'); // Only send cookies over HTTPS
ini_set('session.cookie_httponly', '1'); // Prevent access to cookies via JavaScript (mitigates XSS)
ini_set('session.cookie_samesite', 'Strict'); // Prevent CSRF attacks by restricting cross-site cookie sharing


// Check if the user is logged in
if (!isset($_SESSION['email'])) {
// If not logged in, redirect to login page
header("Location: pages-login.php");
exit();
}

include "db.php";

if (isset($_POST['submit'])) {
Expand Down
15 changes: 15 additions & 0 deletions createBox.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
<?php
// session_start(); // Start the session
session_start();

session_regenerate_id(true); // This will regenerate the session ID and delete the old one
ini_set('session.cookie_secure', '1'); // Only send cookies over HTTPS
ini_set('session.cookie_httponly', '1'); // Prevent access to cookies via JavaScript (mitigates XSS)
ini_set('session.cookie_samesite', 'Strict'); // Prevent CSRF attacks by restricting cross-site cookie sharing


// Check if the user is logged in
if (!isset($_SESSION['email'])) {
// If not logged in, redirect to login page
header("Location: pages-login.php");
exit();
}

include "db.php";

Expand Down
14 changes: 14 additions & 0 deletions createBranch.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
<?php
// session_start(); // Start the session
session_start();

session_regenerate_id(true); // This will regenerate the session ID and delete the old one
ini_set('session.cookie_secure', '1'); // Only send cookies over HTTPS
ini_set('session.cookie_httponly', '1'); // Prevent access to cookies via JavaScript (mitigates XSS)
ini_set('session.cookie_samesite', 'Strict'); // Prevent CSRF attacks by restricting cross-site cookie sharing


// Check if the user is logged in
if (!isset($_SESSION['email'])) {
// If not logged in, redirect to login page
header("Location: pages-login.php");
exit();
}

// Retrieve company ID from URL
$company_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
Expand Down
17 changes: 17 additions & 0 deletions createitem.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
<?php

// session_start(); // Start the session
session_start();

session_regenerate_id(true); // This will regenerate the session ID and delete the old one
ini_set('session.cookie_secure', '1'); // Only send cookies over HTTPS
ini_set('session.cookie_httponly', '1'); // Prevent access to cookies via JavaScript (mitigates XSS)
ini_set('session.cookie_samesite', 'Strict'); // Prevent CSRF attacks by restricting cross-site cookie sharing


// Check if the user is logged in
if (!isset($_SESSION['email'])) {
// If not logged in, redirect to login page
header("Location: pages-login.php");
exit();
}

// Retrieve company ID from URL
$branch = isset($_GET['id']) ? intval($_GET['id']) : 0;

Expand Down
16 changes: 16 additions & 0 deletions delete.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@

<?php
// session_start(); // Start the session
session_start();

session_regenerate_id(true); // This will regenerate the session ID and delete the old one
ini_set('session.cookie_secure', '1'); // Only send cookies over HTTPS
ini_set('session.cookie_httponly', '1'); // Prevent access to cookies via JavaScript (mitigates XSS)
ini_set('session.cookie_samesite', 'Strict'); // Prevent CSRF attacks by restricting cross-site cookie sharing


// Check if the user is logged in
if (!isset($_SESSION['email'])) {
// If not logged in, redirect to login page
header("Location: pages-login.php");
exit();
}

include "db.php";


Expand Down
14 changes: 13 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
<?php
// session_start(); // Start the session

session_start();

session_regenerate_id(true); // This will regenerate the session ID and delete the old one
ini_set('session.cookie_secure', '1'); // Only send cookies over HTTPS
ini_set('session.cookie_httponly', '1'); // Prevent access to cookies via JavaScript (mitigates XSS)
ini_set('session.cookie_samesite', 'Strict'); // Prevent CSRF attacks by restricting cross-site cookie sharing

// Check if the user is logged in
if (!isset($_SESSION['email'])) {
// If not logged in, redirect to login page
header("Location: pages-login.php");
exit();
}
include 'db.php';

// // Check if the user is logged in
Expand Down
16 changes: 16 additions & 0 deletions itemDelete.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
<?php
// session_start(); // Start the session
session_start();

session_regenerate_id(true); // This will regenerate the session ID and delete the old one
ini_set('session.cookie_secure', '1'); // Only send cookies over HTTPS
ini_set('session.cookie_httponly', '1'); // Prevent access to cookies via JavaScript (mitigates XSS)
ini_set('session.cookie_samesite', 'Strict'); // Prevent CSRF attacks by restricting cross-site cookie sharing


// Check if the user is logged in
if (!isset($_SESSION['email'])) {
// If not logged in, redirect to login page
header("Location: pages-login.php");
exit();
}

include "db.php";

if (isset($_GET['id'])) {
Expand Down
15 changes: 15 additions & 0 deletions itemUpdate.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
<?php
// session_start(); // Start the session
session_start();

session_regenerate_id(true); // This will regenerate the session ID and delete the old one
ini_set('session.cookie_secure', '1'); // Only send cookies over HTTPS
ini_set('session.cookie_httponly', '1'); // Prevent access to cookies via JavaScript (mitigates XSS)
ini_set('session.cookie_samesite', 'Strict'); // Prevent CSRF attacks by restricting cross-site cookie sharing


// Check if the user is logged in
if (!isset($_SESSION['email'])) {
// If not logged in, redirect to login page
header("Location: pages-login.php");
exit();
}

include "db.php";

Expand Down
12 changes: 12 additions & 0 deletions logout.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
<?php
session_start();

// Unset all session variables
$_SESSION = array();

// Destroy the session
session_destroy();

// Redirect to login page
header("Location: pages-login.php");
exit();
?>
<!DOCTYPE html>
<html lang="en">

Expand Down
Loading

0 comments on commit 3b059ad

Please sign in to comment.