linuxfront-v2-logistics/logout.php
This script handles user logout for the logistics customer portal. It terminates the session, logs the logout event to the database, clears all session data, and redirects back to the login page.
Purpose
- 🚪 Safely log out the current user.
- 📝 Record the logout timestamp for auditing.
- 🗑️ Clear all session variables to prevent unauthorized access.
- 🔄 Redirect the user to the login screen (
index.php).
Dependencies & Context
- PHP Session API: Uses
session_start()andsession_unset(). - Logging Utility: Calls
logCustomerLoginLogout(true)to record the event . - Session Variables: Relies on variables set during the login process (e.g.,
$_SESSION['Customer_ID']). - Login Page: Redirects to
index.php, which presents the login form.
Implementation Details
This section breaks down the logout script into four steps.
1. Session Initialization
session_start();
- Resumes the existing session or starts a new one.
- Ensures access to
$_SESSIONvariables for cleanup and logging.
2. Logging the Logout Event
logCustomerLoginLogout(true);
- Invokes the logging function with
$is_logout = true. - Updates the
customer_login_logtable’slogout_timefor the currentsession_id.
3. Session Cleanup
unset(
$_SESSION['banyan_enabled'],
$_SESSION['banyan'],
$_SESSION['Customer_ID'],
$_SESSION['Customer_Type'],
$_SESSION['Customer_Billing_ZIP'],
$_SESSION['Customer_email'],
$_SESSION['Customer_Detail_ID'],
$_SESSION['ADMIN_ID_FRONT'],
$_SESSION['ADMIN_NAME_FRONT'],
$_SESSION['Master_Customer_Type'],
$_SESSION['Master_Customer_ID'],
$_SESSION['QUOTE_INFO'],
$_SESSION['shipper_location'],
$_SESSION['consignee_location']
);
session_unset();
unset()removes specific session keys.session_unset()clears all remaining session data.
4. User Redirection
header("location:index.php");
exit();
- Sends an HTTP 302 redirect to
index.php. - Ends script execution to prevent further output.
Session Variables Cleared
| Session Key | Description |
|---|---|
| banyan_enabled | Two-factor authentication enabled flag |
| banyan | Two-factor authentication data |
| Customer_ID | Logged-in customer’s unique ID |
| Customer_Type | Customer role/type (e.g., shipper, consignee) |
| Customer_Billing_ZIP | Billing ZIP code |
| Customer_email | Customer’s email address |
| Customer_Detail_ID | Reference to customer’s detailed profile |
| ADMIN_ID_FRONT | Front-end administrator ID |
| ADMIN_NAME_FRONT | Front-end administrator username |
| Master_Customer_Type | Primary account type (for sub-users) |
| Master_Customer_ID | Primary account ID (for sub-users) |
| QUOTE_INFO | Stored quote details |
| shipper_location | Shipper’s last known location |
| consignee_location | Consignee’s last known location |
Process Flow
flowchart LR
A[Start Session] --> B[Log Logout Event]
B --> C[Clear Specific Session Vars]
C --> D[Unset All Session Data]
D --> E[Redirect to Login (index.php)]
Related Components
- logCustomerLoginLogout(): Updates login/logout records in the database .
- index.php: Entry point and login form for customer portal.
- Authentication Scripts: Typically paired with
login.phpor similar, which sets session variables.
Usage: Include or link to logout.php when providing a “Logout” button or link in the UI. It immediately ends the session and returns users to the login screen.