linuxfront-v2-logistics/frame.php π
This PHP script acts as a secure wrapper for embedding Tech Logistics content inside a parent application. It manages CORS, sessions, cookie consent, and renders a sandboxed <iframe> for cross-domain integration.
π Overview
This file ensures that requests from tms.freightanywhere.com can safely load remote content. It:
- Validates and sets CORS headers
- Handles preflight (OPTIONS) requests
- Manages a custom session (
GMIID) - Displays a cookie consent banner
- Embeds an iframe pointing to
cs_login_cors.php
βοΈ Key Responsibilities
- Prevent premature output with output buffering
- Enforce CORS only for the allowed domain
- Respond to OPTIONS preflight with
204 No Content - Generate or reuse a session ID and set a secure cookie
- Show consent UI if the user has not accepted cookies
- Embed remote content in a sandboxed iframe with dynamic parameters
π Request Flow
flowchart TD
A[Client Request] --> B{Is OPTIONS?}
B -- Yes --> C[204 No Content]
B -- No --> D[Set CORS Headers]
D --> E[Session Handling]
E --> F{Consent Given?}
F -- No --> G[Render Consent Banner]
F -- Yes --> H[Hide Banner]
G & H --> I[Render Sandboxed IFrame]
π Code Breakdown
1. Output Buffering
Begins with ob_start() to prevent any output before headers are sent.
<?php
// Prevent output before headers
ob_start();
This ensures headers (especially CORS) are not blocked by accidental whitespace .
2. CORS Validation & Headers
- Reads the
HTTP_REFERERor defaults tohttp://tms.freightanywhere.com. - Uses a regex to match
tms.freightanywhere.comon HTTP or HTTPS. - Falls back to
https://tms.freightanywhere.comif invalid.
$origin = $_SERVER['HTTP_REFERER'] ?? 'http://tms.freightanywhere.com';
$allowedDomain = 'tms.freightanywhere.com';
if (preg_match("/^https?:\/\/" . preg_quote($allowedDomain, '/') . "(:\d+)?$/", $origin)) {
$allowedOrigin = $origin;
} else {
$allowedOrigin = 'https://tms.freightanywhere.com';
}
header('Access-Control-Allow-Origin: ' . $allowedOrigin);
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Authorization');
This enforces that only the trusted TMS domain can access resources .
3. Preflight (OPTIONS) Handling
Intercepts CORS preflight requests and returns 204 No Content immediately:
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
header('HTTP/1.1 204 No Content');
ob_end_flush();
exit;
}
This prevents further processing and speeds up preflight responses .
4. Session Management π
- Retrieves or generates a 7-digit session ID.
- Calls
session_start()to initialize PHP session. - Sets a custom Secure, HttpOnly, SameSite=None cookie named
GMIID. - Unsets default
PHPSESSIDcookie to avoid conflicts.
$sess_id = session_id() ?: rand(1000000, 9999999);
session_id($sess_id);
session_start();
header("Set-Cookie: GMIID=$sess_id; Path=/; Secure; HttpOnly; SameSite=None");
unset($_COOKIE['PHPSESSID']);
ob_end_flush();
This ensures consistent session tracking across domains .
5. Cookie Consent Banner πͺ
Displays a consent box if $_COOKIE['CookieBy'] !== 'accept'.
if (!isset($_COOKIE['CookieBy']) || $_COOKIE['CookieBy'] !== 'accept') {
echo '<div id="consentBox" class="slideInUp">β¦<button class="consentButton">Refresh</button></div>';
if (isset($_POST['accept'])) {
setcookie('CookieBy', 'accept', time()+30*24*60*60, '/', '', true, true);
header('Location: ' . $_SERVER['PHP_SELF']);
exit;
}
} else {
echo '<style>#consentBox { display: none; }</style>';
}
This gently prompts users to accept before loading the iframe .
6. Consent Handler Script
A tiny JavaScript snippet sends the accept signal via fetch and reloads the page:
<script>
document.querySelector('.consentButton').onclick = () => {
fetch('', {
method: 'POST',
body: new URLSearchParams('accept=true')
}).then(() => location.reload());
};
</script>
This keeps the UX smooth and avoids full form submissions .
7. Sandboxed IFrame Embedding π¦
Based on $_REQUEST['ship_action'], the script builds an <iframe> URL with dynamic query parameters. It uses a sandbox attribute to limit capabilities:
<?php if ($_REQUEST['ship_action']=='edit_shipment') { ?>
<iframe id="ltlshipmentControlleriframe"
sandbox="allow-forms allow-scripts β¦"
src="https://www.techlogistics.com/cs_login_cors.php?
sess_id=<?=$sess_id?>&action=customer_id&β¦&ship_action=edit_shipmentβ¦">
</iframe>
<?php } else { ?>
<iframe id="ltlshipmentControlleriframe"
sandbox="allow-forms allow-scripts β¦"
src="https://www.techlogistics.com/cs_login_cors.php?
sess_id=<?=$sess_id?>&action=customer_id&β¦&active_user_id=<?=$_REQUEST['active_user_id']?>">
</iframe>
<?php } ?>
This loads the remote LTL shipment controller inside a secure, isolated context .
π Integration & Dependencies
- cs_login_cors.php: remote endpoint handling sessionβbased login
- Tech Logistics backend: renders shipment management UI
- TMS domain:
tms.freightanywhere.com
π‘οΈ Security Considerations
- Strict CORS: only allow trusted domain
- Secure cookie:
HttpOnly; SameSite=None - Sandboxed iframe: limits remote content capabilities
- Output buffering: prevents header leakage
This file plays a central role in securely integrating external shipment tools into the Freight Anywhere TMS interface, while preserving session integrity and user consent.