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 aLocationheader toindex.php, which typically hosts the login form.
🔗 Dependencies
- Session Management
Must be loaded aftersession_start(). In most pages,inc/config.php(which callssession_start()) appears before this include. - Short Open Tags
Relies on<?instead of<?php. Ensureshort_open_tagis enabled inphp.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
- Check Session
if (!isset($_SESSION["Customer_ID"])) { … } - Redirect
Immediately send aLocationheader toindex.php. - Stop Further Output
Sinceheader()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 addingexit;afterheader()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.