Software, your way.
How To Get Good Custom Software
(Download)
(PDF)
burger menu icon
WillMaster

WillMaster > LibraryWebsite Automation

FREE! Coding tips, tricks, and treasures.

Possibilities weekly ezine

Get the weekly email website developers read:

 

Your email address

name@example.com
YES! Send Possibilities every week!

Central Prices File For Easy Site-wide Changes

Here is a way to manage product pricing from a central repository. Make a price change in one file and the price is automatically changed on all web pages using the system.

There will be no need to manually change all your web pages every time a price changes.

The central prices repository file is a PHP file.

The PHP file is accessible by each web page that publishes the prices. Price information is selectively extracted from the repository.

The Central Prices Repository File

Here is what the central prices repository PHP file looks like:

<?php
$Building_a_Reputation  = "$12.95";
$CollectingFees         = "$25.50";
$MasterFormManual       = "Free!";
$HandlingClientsVolumnI = "$34.95";
$HandlingClientsVolumnII= "$34.95";
$DoodadWidgetThingy     = "$77.00";
$TinyWidget             = "Free with purchase of Doodad Widget Thingy";
$Ten_Ways_To_Get_Clients= "$27.00";
?>

The file can be created and updated with any plain text processor. NotePad and TextWrangler are examples.

The first and last line are required ("<?php" and "?>"). In between is where you specify your prices, one per line.

This is the format: $Identification = "price";

The identification starts with a dollar symbol ("$") and is composed of letters, digits, and underscore characters. Note: The first character after the dollar symbol must be a letter or an underscore. It may not be a digit.

An equal symbol ("=") is between the identification and the price. There may be zero, one, or more spaces on each side of the equal symbol.

The price is between quotation marks. The price can be specified with any series of characters. It can even be blank (nothing between the quotation marks).

If a quotation mark is part of a price, a backward-slash character needs to precede the quotation mark. Example: $TheHatBook = "Make \"Willie\" an offer";

Your list of identifications and prices may be as small or as large as you require for your website.

Where To Put The Central Prices Repository File

Name the central prices repository file centralprices.txt and upload it to the document root directory of your domain. (The document root is the directory where your main or index web page file is located.)

If you name it different than centralprices.txt or put it into a subdirectory of the document root, adjust the following directions accordingly.

Do not name the file with a .php extension. We don't want the server to process the PHP code until after it has been included into a web page.

How To Insert Prices Into Web Pages

Making Prices Accessible —

The central prices repository file needs to be accessible by each web page that will publish prices contained in the file.

It is made accessible with this PHP code:

<?php include($_SERVER['DOCUMENT_ROOT']."/centralprices.txt"); ?>

That one-line PHP code would generally go into the head area of the web page source code. But it can go into the body area, instead, if that makes sense for your site.

There is only one requirement for where the one-line command goes: Somewhere above the prices it affects.

Inserting A Price Into The Web Page —

Prices are inserted into a web page with PHP code containing the price's identification. Example: <?php echo($CollectingFees) ?>

Where the above PHP code resides is where the price associated with the $CollectingFees identification is inserted. Using the central prices repository example further above, "$25.50" (without the quotes) is printed on the web page.

If the price for the $CollectingFees item is changed in the central prices repository file, the price is automatically changed on web pages containing the price inserting PHP code.

One or many prices may be inserted into a web page, each with its own price insertion PHP code to identify the item and its price.

Making Prices Accessible On Other Domains —

To use a central prices repository file on one domain to update prices on web pages at another domain, the PHP code to make the file accessible is different than the previous instructions.

The different code is allowed on some domains and not on others. It depends on how PHP is configured for the domain. (The "allow_url_include" section at PHP: Runtime Configuration - Manual contains specific information.)

Here is the code to access the central prices repository file on another domain:

<?php include("http://example.com/centralprices.txt"); ?>

The URL is the complete http://... URL to the central prices repository file.

That is the only difference when using the prices file on one domain for web pages on another domain. The PHP code to insert a price does not change.

Using The Central Prices Repository File

Once set up, you will be pleased how easy it is to change prices.

You can run specials or test prices without manually changing the prices on every web page they occur. One change, in one file, and you're good to go.

Will Bontrager

Was this article helpful to you?
(anonymous form)

Support This Website

Some of our support is from people like you who see the value of all that's offered for FREE at this website.

"Yes, let me contribute."

Amount (USD):

Tap to Choose
Contribution
Method

All information in WillMaster Library articles is presented AS-IS.

We only suggest and recommend what we believe is of value. As remuneration for the time and research involved to provide quality links, we generally use affiliate links when we can. Whenever we link to something not our own, you should assume they are affiliate links or that we benefit in some way.

How Can We Help You? balloons
How Can We Help You?
bullet Custom Programming
bullet Ready-Made Software
bullet Technical Support
bullet Possibilities Newsletter
bullet Website "How-To" Info
bullet Useful Information List

© 1998-2001 William and Mari Bontrager
© 2001-2011 Bontrager Connection, LLC
© 2011-2024 Will Bontrager Software LLC