1
General Support / Re: Easiest way to know what is the customer_id from "outside" the AbanteCart env
« on: May 06, 2021, 10:29:40 AM »
Ok, I was able to figure it out by exploring some of the AbanteCart code... Here is what I did, not sure if it is a "best practice" or if things are ugly but so far it seems to work:
(sorry, for some reason I cannot seem to post "code" in the forum)
Quote
<?php
$root_path = dirname(__FILE__);
if (defined('IS_WINDOWS')) {
$root_path = str_replace('\\', '/', $root_path);
}
define('DIR_ROOT', $root_path);
// HTTP
$dirname = rtrim(dirname($_SERVER['PHP_SELF']), '/.\\');
$dirname = strip_tags(html_entity_decode($dirname, ENT_QUOTES, 'UTF-8'));
define('HTTP_SERVER', 'http://'.$_SERVER['HTTP_HOST'].$dirname);
define('HTTP_ABANTECART', 'http://'.$_SERVER['HTTP_HOST'].trim($dirname, 'static_pages'));
// DIR
define('DIR_APP_SECTION', str_replace('\'', '/', realpath(dirname(__FILE__))).'/');
define('DIR_CORE', str_replace('\'', '/', realpath(dirname(__FILE__).'/../')).'/core/');
define('DIR_ABANTECART', str_replace('\'', '/', realpath(DIR_APP_SECTION.'../')).'/');
// Startup
//~ require_once(DIR_ABANTECART.'system/config.php');
//~ require_once(DIR_CORE.'helper/utils.php');
//~ require_once(DIR_CORE.'lib/session.php');
//For some reason, the above directories are not populated on my server, so I hard code them below:
require_once('/mydomain_path/system/config.php');
require_once('/mydomain_path/core/helper/utils.php');
require_once('/mydomain_path/core/lib/session.php');
$from_admin = false;
$session_id = '';
if (isset($_GET['mode']) && $_GET['mode'] == 'admin') {
$from_admin = true;
}
foreach (array_keys($_COOKIE) as $key) {
if ($from_admin === true && preg_match("/^AC_CP/", $key)) {
$session_id = $key;
break;
}
if ($from_admin !== true && preg_match("/^AC_SF/", $key)) {
$session_id = $key;
break;
}
}
define('SESSION_ID', $session_id);
//try to start session.
$session = new ASession(SESSION_ID);
$customerId = 0;
if ((isset($_SESSION['user_id']) || isset($_SESSION['customer_id']))){
$customerId = $session->data['customer_id'];
}
?>
<!DOCTYPE html>
<html>
<body>
<?php
echo "hello, the logged in customer_id is: " . $customerId . ".";
?>
</body>
</html>
(sorry, for some reason I cannot seem to post "code" in the forum)