route.php: Main Request Router
The route.php file serves as the central dispatcher for all incoming requests to the TechLogistics application. It inspects the request’s host, file name, extension, and path, then directs execution to the appropriate handler: API endpoints, asset delivery, CMS pages, or site templates.
🛠️ Configuration
Before any routing logic, the file loads global settings and helper functions.
<?php
include_once("inc/config.php");
- inc/config.php defines constants like
TEMPLATE_DIR,SITE_DIR,TEMPLATE_JS_DIR, andSITE_JS_DIR. - It also starts the session and configures error reporting and database connections .
🚀 API Routing
If the request comes from the dedicated API host, route.php boots up the LTL-quote API.
if ($_SERVER["HTTP_HOST"] == 'api.techlogistics.com') {
include(TEMPLATE_DIR . '/rating_ltlquote_api_v1/rating_ltlquote_api_v1_top.php');
exit;
}
- Purpose: Forward API calls to the rating engine, which auto-submits an LTL quote request form .
- Outcome: Early exit after including
rating_ltlquote_api_v1_top.php.
⚡ Dynamic “Start Quote” Includes
Special routes for quick-start quote forms:
| File Name / Dir | Included From |
|---|---|
| tst.php | TEMPLATE_DIR . '/start_quote/tst.php' |
| *.html under /myPartials | TEMPLATE_DIR . '/start_quote/myPartials/…' |
| *.js under /myScripts | TEMPLATE_DIR . '/start_quote/myScripts/…' |
| *.html under /myPartialss | TEMPLATE_DIR . '/start_quote25/myPartialss/…' |
| *.js under /myScriptss | TEMPLATE_DIR . '/start_quote25/myScriptss/…' |
- Checks
$currnt_file_nameor$file_extensionplus$path_parts['dirname']. - Purpose: Serve quote UI components from template directories.
📦 Excel & File Exports
Handles file downloads (CSV, XLSX, PNG, PDF) from an excel_export folder:
if (in_array($file_extension, ['csv','xlsx','png','pdf'])
&& $path_parts['dirname'] == '/excel_export') {
$name = '/var/www/tech-portals/linuxfront-v2-logistics/excel_export/' . $currnt_file_name;
ob_clean();
$fp = fopen($name, 'rb');
header("Content-Type: " . match($file_extension) {
'png' => 'image/png',
'pdf' => 'application/pdf',
default=> 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
});
header("Content-Length: " . filesize($name));
fpassthru($fp);
exit;
}
- Streams files directly to the client with proper headers.
- Supports multiple extensions with shared logic.
📄 Asset Routing
Delivers HTML partials and JavaScript files from site or template directories:
- HTML Partials
if ($file_extension == 'html' && $path_parts['dirname'] == '/partials') { include(TEMPLATE_DIR . '/inc/partials/' . $currnt_file_name); exit; } - JavaScript Files
if ($file_extension == 'js') { if (file_exists(SITE_DIR . SITE_JS_DIR . $currnt_file_name)) include_once(SITE_DIR . SITE_JS_DIR . $currnt_file_name); elseif (file_exists(TEMPLATE_DIR . TEMPLATE_JS_DIR . $currnt_file_name)) include_once(TEMPLATE_DIR . TEMPLATE_JS_DIR . $currnt_file_name); else echo "No File Exist"; exit; }
- SITE_JS_DIR and TEMPLATE_JS_DIR manage fallback loading.
- If neither exists, outputs a brief error message.
📑 Page Routing & Templates
For requests not matched above, route.php attempts to serve PHP pages or CMS templates:
- Static PHP Includes
if (file_exists(SITE_DIR . $currnt_file_name)) { include_once(SITE_DIR . $currnt_file_name); exit; } elseif (file_exists(TEMPLATE_DIR . 'claim_system/_partial/' . $currnt_file_name)) { include_once(TEMPLATE_DIR . 'claim_system/_partial/' . $currnt_file_name); exit; } - 404 Handling
if (!isset($TEMPLATE[$currnt_file_name])) { $no_breadcrumb = true; include_once("404.php"); } - CMS Pages
$key = pathinfo($currnt_file_name, PATHINFO_FILENAME); $sql = "SELECT * FROM static_pages_trynew WHERE page_key='$key' AND is_active='Y' AND portal='techlogistics.com'"; $res = Query($sql); if (Num($res) > 0) { $currentcmsPage = $key; include_once("cms.php"); } - Popup Templates
$popups = [ 'shippment_detail_v2.php','post_pickup_v2.php', … ]; if (in_array($currnt_file_name, $popups)) { include_once("popup_template.php"); } - Default Site Template
Fallback to:include_once("site_template.php");
- TEMPLATE array governs available non-CMS pages.
- Query() and Num() are global DB helpers.
🔀 Routing Logic Flowchart
flowchart TD
A[Incoming Request] --> B{API Host?}
B -- Yes --> C[Include API Handler<br/>rating_ltlquote_api_v1_top.php]
B -- No --> D{Static Asset?}
D -- Yes --> E[Serve Partials, Scripts,<br/>or Excel Export]
D -- No --> F{Page Exists on Disk?}
F -- Yes --> G[Include Site or Claim Partial]
F -- No --> H{In TEMPLATE Array?}
H -- No --> I[404 Page]
H -- Yes --> J{CMS Page?}
J -- Yes --> K[Include cms.php]
J -- No --> L{Popup Template?}
L -- Yes --> M[Include popup_template.php]
L -- No --> N[Include site_template.php]
route.php implements a classic PHP front controller:
- Flexibly serves API, static assets, and dynamic pages.
- Maintains a clear separation between raw file delivery and templated content.
- Allows easy extension by adding new directories or template rules.