linuxfront-v2-logistics/inc/user_secure.inc.php 🔒

This tiny guard file ensures that only authenticated customers can access protected pages. If a valid session is missing, it immediately redirects the user to the login page.

Code Snippet

<? 
if (!isset($_SESSION["Customer_ID"])) { 
    header("location:index.php"); 
} 
?>

This is the complete content of user_secure.inc.php, as it appears in the codebase.

🛠️ Purpose

  • Authenticate Access
    Blocks access to any page that includes this file unless the user is logged in.
  • Redirect Unauthenticated Users
    Sends a Location header to index.php, which typically hosts the login form.

🔗 Dependencies

  • Session Management
    Must be loaded after session_start(). In most pages, inc/config.php (which calls session_start()) appears before this include.
  • Short Open Tags
    Relies on <? instead of <?php. Ensure short_open_tag is enabled in php.ini.

🚀 Usage

Include this file at the very top of any script that requires a logged-in customer:

<?php
include_once("inc/config.php");        // Starts session, loads config
include_once("inc/user_secure.inc.php"); // Redirects if not logged in
// ...rest of protected page...

Example: In the legacy welcome page, it appears as:

<?php
include_once("inc/config.php");
include_once("inc/user_secure.inc.php");  // ← Protects this page
// ... display welcome dashboard ...
?>

🔍 How It Works

  1. Check Session
    if (!isset($_SESSION["Customer_ID"])) { … }
    
  2. Redirect
    Immediately send a Location header to index.php.
  3. Stop Further Output
    Since header() must be sent before any output, place this include at the top.

📋 Key Elements

Element Role
$_SESSION["Customer_ID"] Holds the authenticated customer ID.
header("location:index.php") Redirects unauthenticated users to login.

⚠️ Best Practices

  • Use Full PHP Tags
    Replace short tags with <?php … ?> for portability.
  • Exit After Redirect
    Consider adding exit; after header() to prevent further script execution.
  • HTTP Status Code
    You may send a 302 status explicitly:
    header("HTTP/1.1 302 Found");
    header("Location: index.php");
    exit;
    

By centralizing this simple authentication check, the application ensures consistency across all protected pages and avoids repetitive code.