From 8201d7804b3a1945594ed1a374f565aa8363d3ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CVeLiTi=E2=80=9D?= <“info@veliti.nl”> Date: Tue, 4 Feb 2025 13:03:27 +0100 Subject: [PATCH] CMXX - Include API authorization in index --- index.php | 16 ++++++++++++++-- products.php | 16 +--------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/index.php b/index.php index 8aef612..232793f 100644 --- a/index.php +++ b/index.php @@ -6,17 +6,29 @@ $base_url = isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] === 'on' || $_SERVER[ $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 './custom/settings/config.php'; // Include functions and connect to the database using PDO MySQL include 'functions.php'; // Include translation file include './custom/translations/translations_'.strtoupper(language_code).'.php'; + +//LOGIN TO API +$data = json_encode(array("username" => "paul@veliti.nl", "password" => "test1234"), JSON_UNESCAPED_UNICODE); +$responses = ioAPIv2('/v2/authorization', $data,''); +//Decode Payload +if (!empty($responses)){$responses = json_decode($responses,true);}else{$responses = '400';} +$clientsecret = $responses['token']; + +//IMAGE URL +$img_url = substr(api_url, 0, -8); + // Connect to MySQL database $pdo = pdo_connect_mysql(); // Output error variable diff --git a/products.php b/products.php index 69a01c0..9681e47 100644 --- a/products.php +++ b/products.php @@ -1,21 +1,7 @@ "paul@veliti.nl", "password" => "test1234"), JSON_UNESCAPED_UNICODE); -$responses = ioAPIv2('/v2/authorization', $data,''); -//Decode Payload -if (!empty($responses)){$responses = json_decode($responses,true);}else{$responses = '400';} -$clientsecret = $responses['token']; - -$img_url = substr(api_url, 0, -8); -//===================================== -//end move to index -//===================================== //Pagination $current_page = isset($_GET['p']) && is_numeric($_GET['p']) ? (int)$_GET['p'] : 1; $num_products_on_each_page = 25; @@ -121,7 +107,7 @@ $view .= '