top image
All About Php Includes
id: 1
Category: PHP
Rated:Rating 0 Rating 1 Rating 2 Rating 3 Rating 4
Rate:



Yeah, there is a million tutorials out there on PHP includes, what makes ours different? Well, we plan on breaking it down a little more, giving you more options, and how to fix possible errors rather then throwing the code at you and saying "insert url here".

What does a PHP include do? The basic idea is to place another page/code on another page or more then one page. There is more then one code to do this with. The most common PHP include:

<?PHP
include("URL HERE");
?>

URL HERE Is where you place your URL. Quotations are not needed for this to work all the time either.

Another way you can write this that you don’t normally see is replacing the word Include for Require. It would look like this:

<?PHP
require("URL HERE");
?>

You are able to have as many includes on a page you want.

URLs...you must place an URL inside where it says URL HERE, otherwise it wont work. How this URL is written however, can be important with many hosts. (This is the most common way to fix the error when you type http://www. and it doesn’t work)

Most people are used to writing http://www.domain.com this doesn’t always work. Sometimes you must use the direct link right off your server. But what do I mean by this?

Lets say...we have 2 folders and 3 files in both so it would look like this...

  • index.php
  • home.html
  • Cat
    • spieces.php
    • about.php
    • chome.php
  • Dog
    • spieces.php
    • about.php
    • dhome.php

Cat and Dog would be the folders while there is an index and home page as well. Starting with index.php, let’s say I want it to include home.html on this page, using the direct url of course.

<?PHP
include("home.html");
?>

There is no http://www. in this URL at all. That was easy enough; let’s say from the index.php we click on a link taking us to the home of the cats section (Cat/home.php). Home.php is the main page, but I want it to have the dog home page as well under it, creating a "pet home" page in a sense. Displaying the home page of both dog and cat on the cat home page.

But...the dog is a folder up...I can't have it "dhome.php", it shows up as not available or not existing.

../ Is a command that tells you to move up one folder. We need to go to the main folder and then to the Dog folder then to the page. (up to main - > Dog -> dhome.php)

<?PHP
include("../Dog/dhome.php");
?>

You are able to move up as many folders as you want. I could even do this if I wanted to (though would be pointless...)

<?PHP
include("Dog/../Cat/../home.php");
?>

Thats all there really is to know about includes. If you need more help you can use the contact form.




Disclaimer

All contents are © Dice.
If credit for anything is missing please contact me and it will be added. If there is something you wish me to take off the site (that belongs to you) contact me. It will be removed immediatly.

Basic Rules

All tutorials on this site were written by me, Dice. They may not be redistributed without permission! Feel free to link to the videos.

I have used this site also for a project in college :3



home page

Contact Us

About Us