PHP Include not working

2019-09-21 18:57发布

I am trying to use PHP's include function in conjunction with html but it is not working. I'm just messing around with the tag, it seems to be very simple but i cannot figure out why it is not working...

here is the template.php page:

    <!DOCTYPE html>
    <html>
    <head>
        <title>Template</title>
        <link href="css/layout.css"  type="text/css" rel="stylesheet" />
    </head>
    <body>

      <div id="wrapper">

          <?php 
           include ("include/header.php");
           include ("include/leftcolumn.php"); 
           include ("include/rightcolumn.php"); 
           include ("include/footer.php"); 
           ?> 

     </div>


    </body>
    </html>

and here is the header.php page that I am trying to include:

<header>
<p>Header.</p>
</header>

The only thing i could think of is the wrong directory, I have an include folder which is where the header.php is and referenced that in the include tag...unless I'm wrong, any tips? Thanks

directory folder image

标签: php html include
4条回答
别忘想泡老子
2楼-- · 2019-09-21 19:34

Remove your Brackets ()

<!DOCTYPE html>
    <html>
    <head>
        <title>Template</title>
        <link href="css/layout.css"  type="text/css" rel="stylesheet" />
    </head>
    <body>

      <div id="wrapper">

          <?php 
    // removing brackets... hopefully it will be working....
           include "include/header.php";
           include "include/leftcolumn.php"; 
           include "include/rightcolumn.php"; 
           include "include/footer.php"; 
           ?> 

     </div>


    </body>
    </html>
查看更多
爷、活的狠高调
3楼-- · 2019-09-21 19:50

I didn't tested your code, but be sure of your path (is your template.php file to the root, before your include folder?) (it's crazy to say, but pathing are a frequent problem, and it can easily making you mad)

Or, try this syntax too : include 'include/footer.php';

查看更多
看我几分像从前
4楼-- · 2019-09-21 19:55

Remove Space

include("include/header.php");
查看更多
萌系小妹纸
5楼-- · 2019-09-21 19:59

http://php.net/manual/en/function.include.php you dont need to use parenthesis try :

<?php 
           include "include/header.php";
           include "include/leftcolumn.php"; 
           include "include/rightcolumn.php"; 
           include "include/footer.php"; 
           ?> 

and make sure the paths correct.

edit:

every exemple on the php manuel are dont have parenthesis.

And a question. where exectly you try to execute your php file. just in a browser or using any wamp server aplication to simulate server side action for your php ?

查看更多
登录 后发表回答