Example : How to insert all Php file contents as it is, in another Php file/page at required place ?

header.php

   Menu Bar Related Code
   <?php
      echo '<a href="/index.php">Home</a> ||
            <a href="course.php">Course Tutorial</a> ||
            <a href="project.php">Project</a> ||
            <a href="androids.php">Androids</a> ||
            <a href="gallery.php">Gallery</a>';
   ?>
-------------------------------------------------------------
connectivity.php

<?php
   error_reporting(E_ERROR | E_PARSE); 
   $conn=mysqli_connect("localhost","MySqlUserName","MySqlPassword",
   "MySqlDatabasename");
        if ($conn)
          {
           echo "database connected successfully","<br>";
          }
        else
          {
           die("Connection Aborted:" . mysqli_connect_error());
          }
    
     mysqli_close($conn);    
?>
-------------------------------------------------------------
footer.php
   Footer related Code

<?php
   echo "<div>Copyright &copy; 2020-" . " All Copyright Reserved</div>";
?>

-------------------------------------------------------------
-------------------------------------------------------------

<!DOCTYPE html>
<html>
	<body>
		<h2>Welcome to Codershelpline</h2>
			
		<div>Header Section Area</div>
		   <?php include 'header.php';?>
			
		   <?php include 'connectivity.php';?>

		<div>Body Part Code</div>
			
		<div>Footer Section Area</div>
		   <?php include 'footer.php';?>		
	</body>
</html>

NB : We can use ‘require’ in place of ‘include’ also. for more details about them see difference between option.

Loading

Categories: Php Proj

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.