0

This may seems to be a silly mistake or my sheer ignorance about PHP basis. I have read some other question on stackoverflow regarding the same problem I'm facing, but it didn't help me much.

includes in php

unable to Include Files php using include

My problem:

I am trying to include a header.php file which is located in my "include folder" onto my index.php file which is in the root folder.

index.php file content:

</head>

<body id="page1">
    <!--==============================header=================================-->
    <header>
        <?
        include("include/header.php");
        ?>  
    </header><div class="ic">

In the design view on Dreamweaver I can see the header is being included. However, when I am trying to see the page on localhost (WAMP server). I can't see the header is being displayed and I am not getting any error message either.

1
  • 2
    make sure the file's actually in place on the server. try a require() instead, which'd throw a fatal error if the file can't be included. if it's a shorttags, you'd be able to see the php code in your browsers "view source". Commented Mar 11, 2013 at 18:56

1 Answer 1

3

Don't use <? but <?php

Depending on how your Apache is configured that might not work. Avoid short tags always.

Sign up to request clarification or add additional context in comments.

4 Comments

Gotcha. I tried and it worked. However, just for my knowledge how can someone configure Apache so that it can recognize short tags.
You are always better using full tags. If tomorrow you upload your programme to another server, you don't want to waste time changing the apache config file (in case you want) or editing all your files and replacing the short tags. Full tags are universal, and universal is good.
Yes, short tags are evil. Listen to @ikaros45 that said, it s php.ini directive: short_open_tag
As @ikaros45 pointed out, universal is the best method. When I started out with PHP, I used short tags and came across many 'complex' problems that can be avoided by just adding 'php' onto your tag!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.