Files
Commerce/index.php
“VeLiTi” 6f1cc27ec4 Initial commit
2025-01-30 11:43:37 +01:00

96 lines
3.5 KiB
PHP

<?php
define('MorvalWatches', true);
// Determine the base URL
$base_url = isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] === 'on' || $_SERVER['HTTPS'] === 1) || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' ? 'https' : 'http';
$base_url .= '://' . rtrim($_SERVER['HTTP_HOST'], '/');
$base_url .= $_SERVER['SERVER_PORT'] == 80 || $_SERVER['SERVER_PORT'] == 443 || strpos($_SERVER['HTTP_HOST'], ':') !== false ? '' : ':' . $_SERVER['SERVER_PORT'];
$base_url .= '/' . ltrim(substr(str_replace('\\', '/', realpath(__DIR__)), strlen($_SERVER['DOCUMENT_ROOT'])), '/');
define('base_url', rtrim($base_url, '/') . '/');
// If somehow the above URL fails to resolve the correct URL, you can simply comment out the below line and manually specifiy the URL to the system.
// define('base_url', 'http://yourdomain.com/shoppingcart/');
// Initialize a new session
session_start();
// Include the configuration file, this contains settings you can change.
include 'config.php';
// Include functions and connect to the database using PDO MySQL
include 'functions.php';
// Include translation file
include './custom/translations_'.strtoupper(language_code).'.php';
// Connect to MySQL database
$pdo = pdo_connect_mysql();
// Output error variable
$error = '';
//error reporting
if (debug){
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
}
//Age consent session
if (isset($_POST['age_consent_allow'])){$_SESSION["age_consent"] = 1;}
// Banner
if (isset($_POST['banner_stay'])){$_SESSION["banner"] = 1;}
if (isset($_POST['banner_move'])){
session_destroy();
header('location: '.banner_link.'');
die();
}
// Define all the routes for all pages
$url = routes([
'/' => 'home.php',
'/about' => 'about.php',
'/about_morval' => 'about_morval.php',
'/product/{id}' => 'product.php',
'/product/{id}/{option_id}' => 'product.php',
'/products' => 'products.php',
'/products/{category}' => 'products.php',
'/products/{category}/{sort}' => 'products.php',
'/products/{p}/{category}/{sort}' => 'products.php',
'/myaccount' => 'myaccount.php',
'/myaccount/{tab}' => 'myaccount.php',
'/download/{id}' => 'download.php',
'/cart' => 'cart.php',
'/cart/{remove}' => 'cart.php',
'/checkout' => 'checkout.php',
'/placeorder' => 'placeorder.php',
'/placeorder/{order_id}' => 'placeorder.php',
'/search/{query}' => 'search.php',
'/logout' => 'logout.php',
'/termsandconditions'=> 'termsandconditions.php',
'/termsandconditions/{download}'=> 'termsandconditions.php',
'/faq'=> 'faq.php',
'/privacy'=> 'privacy.php',
'/privacy/{download}'=> 'privacy.php',
'instructions-for-use' => 'faq.php'
]);
// Check if route exists
if ($url) {
include $url;
} else {
// Page is set to home (home.php) by default, so when the visitor visits that will be the page they see.
$page = isset($_GET['page']) && file_exists($_GET['page'] . '.php') ? $_GET['page'] : 'home';
// Include the requested page
include $page . '.php';
}
//debuglog
if (log_usage){
//GET REMOTE ADRESS
$user_1 = $_SERVER['REMOTE_ADDR'] ?? '<none>';
$user_2 = $_SERVER['HTTP_X_FORWARDED_FOR'] ?? '<none>';
//GET PAGE DETAILS
$page = $_SERVER['REQUEST_URI'] ?? '<none>';
$date = date('Y-m-d H:i:s');
//CREATE LOG MESSAGE
$message = $date.';'.$page.';'.$user_1.';'.$user_2;
//UPDATE LOGFILE
debuglog($message);
}
?>