php include file from another folder

Today, We want to share with you php include.In this post we will show you PHP require_once, include_once() statement, hear for php include_once we will give you demo and example for implement.In this post, we will learn about PHP Include and Require commands with an example.

How to Make Your PHP include File and Gain Functionalities?

PHP Includes:– PHP includes keyword is used to import a php file into another second file of the same as root folder. This reduces time as well as rewriting of access code instead of copy as well as paste strategy. Therefo i recommend to use this includes keyword to evaluate a specific php file which you required to includes in your file.

Read Also:  PHP MySQL Infinite Scroll Pagination

Example of PHP Include//profile.php

Example 1:

<?Php include ("header.php");?>

Example 2: Illustration of header.php file.

<?Php
echo "hello php";
?>

Usage of Statements: Examples

<html>  
    <body>    
      <h2>Welcome! - www.pakainfo.com</h2>  
      <?php 
        require 'footer.php';  
        echo "I have a " . $product1 . " " . $product2 . ".";
      ?>    
  </body>  
</html>

use the PHP includes statement:

footer.php

<html>  
  <body>    
    <h2>Welcome! - www.pakainfo.com</h2>   
    <p>Text line.</p>
    <p>Texty text line.</p>
    <?php include 'footer.php';?>    
  </body>  
</html>

PHP include() Statement

Syntax:

include('name of the php file with path');

File get_product_info.php:

<?php
$product1 = "Mobile";
$product2 = "Laptop";
?>

File index.php, which includes get_product_info.php :

<?php
include('get_product_info.php');
echo "I Virat ".  $product1 ." 
than ".  $product2;
?>

Results

I Virat Mobile  than Laptop

I hope you get an idea about PHP Includes and Require (php require file in different directory).
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.