Go Back   Gaming Gutter > Non-Gaming > Programming > Tutorials


Tutorials - Looking for programming tutorials to increase your knowledge? Do so here.

» Site Navigation
» Home
» FAQ
» Log in
User Name:

Password:

Not a member yet?
Register Now!
» Advertisement
» Recent Threads
Go to first new post [S]elling some painted...
Yesterday 06:30 PM
Last post by CrazySpades
Today 03:30 PM
8 Replies, 9 Views
Go to first new post Fair trade? (maple and...
Today 03:12 PM
by Lanbo
Last post by drdd10
Today 03:17 PM
1 Replies, 2 Views
Go to first new post Selling Legit Gaia items...
Today 03:17 PM
by Icee
Last post by Icee
Today 03:17 PM
0 Replies, 1 Views
Go to first new post Transfering Money to...
08-10-2008 06:03 PM
by Saint
Last post by Saint
Today 03:13 PM
7 Replies, 8 Views
Go to first new post Google Chrome
Today 03:10 PM
by Saint
Last post by Connor
Today 03:11 PM
1 Replies, 2 Views
Reply
 
LinkBack Thread Tools Display Modes

 A Guide To PHP Includes - (MEGA Tutorial)
Old 10-18-2006, 03:55 PM   #1 (permalink)
Oosband
Guest
 
Posts: n/a
iTrader: / %
A Guide To PHP Includes - (MEGA Tutorial)

This is an advanced tutorial about the Include function.

This is really useful if you want to create a load of web pages and have data on them that is subject to change.
For example, if I own a company and I have about 200 pages for my website, each page has my contact email. If my email changed and I needed to change that detail on my site, I would have to edit 200 pages.

Ready?

Step 1
Open your favorite HTML editor and copy this code into it;

Code:
<?php

$company_name = "Oosbandz";
$contact_email = "contact@oosbandz.com";
$conact_name = "Oosband McOosbandz";
$url = "http://www.oosbandz.com";
$copyright = "Oosbandz 2006, All Rights Reserved";
$phone_number = "0800 666666";
$address_1 = "00 Oosbandz Road";
$address_2 = "Oosbandz, UK";

$header = "header1.gif";
$css = "style4.css";
$stats = "stats.php";
?>
Obviously all that data is made up XD

Save that file as data.php

---

Step 2
Open up any pages you want to include any of the data above on.
Add this code to the top of the page;

Code:
<?php include("path/to/data.php"); ?>
Use the directory folder and don't hyperlink.
Example:
(/files/data.php") - Right
(http://www.oosbandz.com/files/data.php") - Wrong

To show the data on your pages add this code to where ever you want it to appear on the web page;

Code:
<?php echo $phone_number; ?>
That will diplay the data in the "Phone Number" tag.

This method will save you so much time in updating pages, now you only need to update one file at a time.

---

Step 2.5

You may have noticed I added 3 files to the bottom of data.php.
These don't have to be included but I will show you why I put them there.

If I wanted my pages to have different CSS style sheets, I could place a load of .css files in the same directory as the data.php files, and just load which ever one I wanted by using the same code:

Code:
<?php echo $css; ?>
That will load the css file I specified.

This same method can be used for practicly anything. Think of all the fun you could have, you can resize images, create different tables, different header files.

---

Notes

You connot have spaces in the $header (example) tags, instead just use an underscore "_".

The $header (example) tags are case sensitive, meaning $header and $Header would be different items.

Instead of using
Code:
<?php echo $example; ?>
you can use
Code:
<? = $example; ?>
. It does exactly the same thing, just with less characters.
  Reply With Quote

 
Old 10-31-2006, 05:11 AM   #2 (permalink)
unlimitedorb
Guest
 
Posts: n/a
iTrader: / %
Nice although you should look into security validations as well.
  Reply With Quote

 Re: A Guide To PHP Includes - (MEGA Tutorial)
Old 11-15-2006, 11:11 AM   #3 (permalink)
gommle gommle is offline Gender Male
Underground
 
gommle's Avatar
 
gommle is offline
Join Date: Sep 2006
Location: The o great land of Nooooooreeeway
Age: 20
Posts: 657
iTrader: 0 / 0%
gommle Is Recognizable
Rep Power: 6
Re: A Guide To PHP Includes - (MEGA Tutorial)

W00t? That script is completely secure.

You would only have to add some extra security if your script was like this:
PHP Code:
top of page ...
<?php
// Include the page specified. 
// go=.htaccess would include all the contents of the file .htaccess
if(!include $_POST['page']){ echo "Page not found!"; }
?>
... end of page
As you can see in the example there would be a huge security risk for any file that's not parsed by the server.
  Reply With Quote
Reply

Bookmarks



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cutting Tutorial Drown Tutorials 6 01-02-2007 11:03 PM
Pop-Out Sig Tutorial Drown Tutorials 7 11-27-2006 11:08 PM
Full Signature Tutorial imported_Sid Tutorials 6 09-19-2006 03:48 PM

Powered by vBadvanced CMPS v3.0 RC2

All times are GMT -7. The time now is 03:31 PM.


vBulletin skin developed by: eXtremepixels
The contents of this webpage are copyright © 2006-2008 GamingGutter.com. All Rights Reserved.

Page generated in 0.11972904 seconds (100.00% PHP - 0% MySQL) with 20 queries