Jump to content

Rewrite of my appication/ globals file


mo

Recommended Posts

I want to rewrite my shopping cart/admin control panel to make the code cleaner, etc. for when I distribute. I wrote my original application on the fly as I was learning PHP.

 

I wanted rewrite in PHP OO but I just cannot see the benefit or wrap my head around OO.

 

One of my issues is my globals file where I define a bunch of global variables that I use to control the configuration of my cart application.

 

My globa file looks like the following and is included in all my application's PHP files like "require_once './config/global.php';"

 

I want o have the global variables in my database and read them once from the DB into the global variables and if I change a value in the DB, I want the global variable to be updated. Also I think there is a better way to handle my db connection as I think the connection happens every time a page loads.

 

 

**global.php**

<?php
session_start();

if(!$_SESSION['WebBrowser']){
$_SESSION['WebBrowser'] = determine_browser();
}

//error_reporting(E_ALL & ~E_NOTICE);

putenv("TZ=US/Eastern");

define('MY_ROOT', dirname(dirname(__FILE__)));
define('CONFIG_ROOT', dirname(__FILE__));
define('INC_ROOT', dirname(dirname(__FILE__))."/inc");
define('ADMIN_ROOT', dirname(dirname(__FILE__))."/admin");
define('P_ROOT', dirname(dirname(__FILE__))."/bp");

//Global variables
$sid = session_id();
$site_id           = 'ABC123';
$other variables.....

//Database Configuration
$database[dbserver] = "123abchost.host.com";
$database[dbuser]   = "user1"; 
$database[dbname]   = "testdb"; 
$database[dbpass]   = "pass1";

require_once CONFIG_ROOT.'/db.php';

/********************************************************************************************************
*                                     Cart Settings                                                                 *
* Global variables for cart
*********************************************************************************************************/
$salesTaxRate = round("0.07",2);
$currency       = 'USD';

$allowAdvancedOrders = 'Y';

etc..........
?>

db.php

<?php
require_once CONFIG_ROOT.'/global.php';

$connect = mysql_connect($database['dbserver'], $database['dbuser'], $database['dbpass']); 
$select= mysql_select_db($database['dbname']); 
//; 
?>

Link to comment
https://forums.phpfreaks.com/topic/180403-rewrite-of-my-appication-globals-file/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.