To make a website more functional and easier to maintain you need to use includes. This allows you to edit one file which will update any page which includes that file. Below is an example of a typical file that is included:
Menu.php
Code :
Now if you were to include that menu.php file within an index.php file:
Code :
If you were to then view source you would see:
Output:
If you use an include link and the file does not exist it will only throw a warning message. If you want to stop the page running when a file cannot be found use require:
Code :
In the case above the echo statement would never appear, as the code will stop running at that point.
Sometimes you might want to include a file that is a level higher, so you might be in http://www.yourdomain.com/subfolder/file.php and you want to include a file found at http://www.yourdomain.com/menu.php you will need to use:
Code :
For every 'level' you wish to go uo you need to use "../". This concludes another tutorial, hopefully there will be some scripts available for use soon!
|
|
||
|
|
To post comments you must sign in to your account below!
If you do not currently have an account click here to create one now!