In PHP, you can also use the “Require” command in place of Include.
The major difference between the two is that using Require will stop the script from running (the page won’t load completely) if it cannot find the page that is referenced for inclusion.
An Include will allow the page to load, but it will just ignore the included code if it cannot be found.
Now let’s mesh it all together in an example!
Imagine this...you are building a website.
Your Greatest Undertaking Of A Website.
200 Pages. 400 Articles. Writing Code By Hand. The Titan Of Websites.
You want to put advertising on each page (We’ll use GoogleTM AdSense as an example).
You also want to test different color themes on the ad code, or change the ads periodically.
You are also going to be quite generous and give copies of this website away for others to use.
The questions start filling your mind...how can I easily change the ad colors or format?
How can I let other people easily put in their AdSense publisher code?
We’ll use Variables and Includes to solve the problem!
Open up 2 blank text documents.
The first one is going to be a settings file, the second one is going to be your Ad code.
In the settings file, you are going to want to set variables for things you know you are going to want to change, the main thing being the AdSense publisher code and the ad link colors.
So, we’ll set the variables as below...
<?php $ad_pub_num = “pub-0123456789”; $eb_linkcolor = “006699”; ?>
The variable, $ad_pub_num, now reflects the AdSense publisher tracking code, and the link colors are the HTML color code 006699, which is a dark blue.
Save this page as settings.php.
To be continued in the next post...
1 Comment
3/31/2011 05:53:09 pm
Money is not everything. There’s Mastercard & Visa.
Reply
Leave a Reply. |
David Rentson
If this free PHP and MYSQL Tutorial is helpful for you... Great! Archives
October 2008
Categories
All
|