PHP include
Submitted by joken on Monday, December 9, 2013 - 16:14.
In PHP, it is necessary to use PHP include command. Because include takes a file name and simply inserts that file content into the script that issued the include command. Including files saves a lot of work, it means that you can create a standard header, footer and menu file that is available to all web pages. And when you want to create a new web page, you do not need to type all the headers and menus that is available to your web page, but instead you only need to include those files you want to include in your script.
At this time, we’re going to create a new PHP file called menu.php and add the following code:
This code below will echo some menus available to our web page.
Next, we also need to create a new PHP file called index.php and add the following code:
In this code below, we take advantage of the include command to add our common menu.
After executing all the code above. It will give an output that looks like as shown below.
menu.php code:
- <?php
- echo '<a href="/default.php">Home</a> *
- <a href="/tutorials.php">Programming</a> *
- <a href="/references.php">Mobile</a> *
- <a href="/examples.php">Blog</a> *
- <a href="/about.php">Articles</a> *
- <a href="/contact.php">Tutorials</a>';
- ?>
index.php:
- <html>
- <body>
- <div>
- <!—this line of code we call the menu.php file using include-->
- <?php include 'menu.php'; ?>
- </div>
- <h1>PHP programming is fun!</h1>
- </body>
- </html>
Outout

What the visitors can see?
When we are using the include command to insert a menu on every web page, the visitor can see only the index.php when they view the page source it will look like as shown below.Comments
Add new comment
- Add new comment
- 30 views