Social Networking Site: Reusing of Codes using PHP Include
Submitted by GeePee on Thursday, March 19, 2015 - 22:08.
In this tutorial I'm going to show you how to reuse of codes using PHP includes, this including of files saves a lot of work. Since we are using a standard Header and Footer this is the best time to apply this concept. So that later on, if you need to update the header you can simply update the header include file not all the pages that has same header.
To start with tutorial, open first our project called “philsocial”. Then open the “home.php” file and cut all the codes found in the header section and it looks like as shown below.
Then we’re going to create a new PHP file called “header.php” and we will paste the code we cut from “home.php”.
Then we will add a single line of code in the home.php under this line
Next we can do all the process above to apply this in all our web pages that has the same header.
If you want to see more of my works, new Source Code or Application and Tutorials Just click here.
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta name="description" content="">
- <meta name="author" content="">
- <link rel="shortcut icon" href="">
- <title>Philsocial</title>
- <!-- Bootstrap core CSS -->
- <link href="css/bootstrap.css" rel="stylesheet">
- <!-- Custom styles for this template -->
- <link href="jumbotron.css" rel="stylesheet">
- <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
- <!--[if lt IE 9]>
- <script src="../../assets/js/html5shiv.js"></script>
- <script src="../../assets/js/respond.min.js"></script>
- <![endif]-->
- <?php
- //login confirmation
- confirm_logged_in();
- ?>
- .table th, .table td {
- border-top: none;
- }
- </head>
- <body>
- <div class="navbar navbar-inverse navbar-fixed-top">
- <div class="container">
- <div class="navbar-header">
- <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- <span class="icon-bar"></span>
- </button>
- <a class="navbar-brand" href="home.php"><B>Philsocial</B></a>
- </div>
- <form class="navbar-form navbar-left">
- <div class="form-group">
- <div class="rows">
- <input type="search" placeholder="search" class="form-control" size="40">
- </div>
- </div>
- </form>
- <div class="navbar-collapse collapse">
- <form class="navbar-form navbar-right">
- <ul class="nav navbar-nav">
- <li class="active"><a href="home.php">Home</a></li>
- <li class="dropdown">
- <a href="#" class="dropdown-toggle" data-toggle="dropdown">
- <?php
- //retrieve session variable
- echo $_SESSION['fName'];?>
- <b class="caret"></b>
- </a>
- <ul class="dropdown-menu">
- <li><a href="#">My Profile</a></li>
- <li><a href="#">Edit profile</a></li>
- <li><a href="#">Edit profile Picture</a></li>
- <li><a href="#">Customize profile</a></li>
- <li><a href="#">Edit Work and Education</a></li>
- </ul>
- </li>
- <li class="dropdown">
- <a href="#" class="dropdown-toggle" data-toggle="dropdown">Account<b class="caret"></b></a>
- <ul class="dropdown-menu">
- <li><a href="#">Account Settings</a></li>
- <li><a href="#">Privacy Settings</a></li>
- <li><a href="#">Manage Social Accounts</a></li>
- <li><a href="#">Manage Credits</a></li>
- <li><a href="logout.php">Logout</a></li>
- </ul>
- </li>
- </ul>
- </form>
- </div><!--/.navbar-collapse -->
- </div>
- </div>
require_once("includes/initialize.php");
. And heres the following code:
This code below simply calls the header.php file.
- <?php
- require_once("includes/initialize.php");
- include 'header.php';
- ?>
Add new comment
- 170 views