PHP tutorials
I´ve been asked several times how to solve this problem.
Let´s say you have folder which stores files with the content of the pages.
You also have an index.php page from which you send requests via url to display a relevant page. See demo.
This tutorial explains one of the approaches this can be done.
Within your site´s root folder create a folder called pages. Inside of this folder create five pages and provide them with some content:
home.php
about_us.php
services.php
testimonials.php
contact_us.php
In the site´s root folder create file and give it a name of index.php.
Open index.php in any text editor and copy and paste the following content:
This piece of code contains the standard html page structure, some styling and navigation which will send a parameter via url. After the closing </p> tag type:
This simple code does the entire work.
First condition checks if there is a pg parameter passed via url and if it is not empty by using:
if condition isn´t true (else) then it includes the default, home page:
If condition is true than parameter is assigned to a variable:
and another condition checks whether the file with the value of the parameter exists in the pages folder:
if it does then this file is included on the page by using:
if file doesn´t exist then the message is displayed
This is one of many ways you can use include function to populate information from external files by selecting them using url parameter.
Website Design Company | Website Design Company Sussex | Website Design Company Chichester | Website Design Packages | Tutorials Resources | Articles | Contact
© Web Design Tutorials – Sebastian Sulinski