简体   繁体   中英

php include file doesnt work

i made header.php file and i wanted to include it in index.php file ..here the code

<body id="home">
    <section class="container-fluid">
        <div class="content row">
            <section class="main col col-lg-8 col-sm-8">                
               <?php include"_/components/php/header.php"; ?>
            </section><!--main  -->
            <section class="sidebar col col-lg-4 col-sm-4">

            </section><!--sidebar  -->
        </div><!-- content -->
    </section><!-- container -->

but when display the page it doesn't work properly..here what i see in html inspector

<section class="main col col-lg-8 col-sm-8">                
               <!--?php include"_/components/php/header.php"; ?-->

</section>

use include 'blabla.php'; or include('blabla.php'); (with space or brackets) . If still not works then there must be a problem in your main php file which you are including.

Problem

First, move you page to your local server folder so that PHP can be parsed by the server and generate HTML..then :

   <?php include"_/components/php/header.php"; 
           /*   ^^ add space here */ ?>

Solution :

 <?php include "_/components/php/header.php";  /* with space*/ ?>

Also, its a better practice to use include_once if your page contains classes or even a common, general purpose HTML!!

Simply use this one..

include("header.php");

you don't have to require to give full path from public_html/ simple give file name in argument, you can place your header file on "public_html/header.php" location

you can give complete path of your root directory as follows

<?php include $_SERVER['DOCUMENT_ROOT]."some_folder/components/php/header.php"; ?>

here some _folder is optional if you have folder in root. give the name here just as component

$_SERVER['DOCUMENT_ROOT] will gives you the path of your root directory(public_html)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM