I have a simple php file with the following
<?php
require ($_SERVER['DOCUMENT_ROOT'] . '/assets/includes/inc.init.php');
$username = $_GET['username'];
$password = hash('sha256', $_GET['password']);
echo $ecom->userManagement->doLogin($username, $password) == null;
this is suppose to print a simple number 0 or 1.
but for some reason it wants to tell me the ecom class is already in use
Fatal error: Cannot declare class Ecom, because the name is already in use in /var/www/html/core/class.ecom.php on line 19
here is the inc.init.php file
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
date_default_timezone_set("UTC");
//TODO: Check Session
$config = parse_ini_file('config.ini');
$mysqli = new mysqli($config['db_host'], $config['db_user'], $config['db_password'], $config['db_name']);
/* check connection */
if ($mysqli->connect_errno) {
printf("Connect failed: %s
", $mysqli->connect_error);
exit();
}
require($_SERVER['DOCUMENT_ROOT'] . '/core/class.ecom.php');
$ecom = new Ecom($mysqli);
//TODO: Move the creation to when an item is added.
$cart = null;
if(isset($_COOKIE['cart_key'])) {
$cart = $ecom->cartManagement->getCart($_COOKIE['cart_key']);
if(!$cart->check()) {
$cart->delete();
$cart = $ecom->cartManagement->create($_SERVER['REMOTE_ADDR']);
setcookie('cart_key', $cart->key, time()+60*60*24*365, '/', 'domain.com');
}
} else {
$cart = $ecom->cartManagement->create($_SERVER['REMOTE_ADDR']);
setcookie('cart_key', $cart->key, time()+60*60*24*365, '/', 'domain.com');
}
$cart->updateExpiration();
?>
the ecom class is only ever called once and declared once.
require($_SERVER['DOCUMENT_ROOT'] . '/core/class.ecom.php');
$ecom = new Ecom($mysqli);
i have a similar file that works just fine that looks like this
<?php
require ($_SERVER['DOCUMENT_ROOT'] . '/assets/includes/inc.init.php');
$type = $_GET['type'];
if($type == "add") {
$cart->addItem($_GET['id']);
}
else if($type == "remove") {
$cart->removeItem($_GET['id']);
}
else if($type == "update") {
$cart->updateItems();
}
echo 0;