-4

So I created a header.php file to store the basic html markup, but when I try to include it in my php code it just doesn't work. The output is as is like my code on my text editor.

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

            <section class="main-container">
                <div class="main-wrapper">
                    <h2>HOME</h2>
                </div>
            </section>
        </body>
    </html>
Ndroid21
  • 400
  • 1
  • 8
  • 19
mNm
  • 19
  • 4
  • 4
    `?php` need to be ` – Alive to die - Anant Oct 09 '17 at 04:47
  • If it isn't the typo issue perhaps the file isn't PHP, you aren't running it through a server, or PHP isn't installed. If you ever see ` – chris85 Oct 09 '17 at 04:49
  • is your page showing something like `?php.....` ? – mrid Oct 09 '17 at 04:50
  • 2
    Seems OP is MIA – Rotimi Oct 09 '17 at 04:52
  • I assume that you are a developer. Saying that it doesn't work is not helpful at all. Ever heard of debugging? – Rotimi Oct 09 '17 at 04:57
  • Hi all i really appreciate your answers and to be honest ive tried all those stuff that you mentioned before come here im not a genius developer and im just triying to learn my way back to programming as well. the header file is in the main directory along with my index.php file . there is no TYPO as well – mNm Oct 09 '17 at 05:05
  • hi akintunde no im not a developer at all and im just starting to code. and yes ive heard about debugging as well. im saying that it doesnt work really because it just doesnt work on my end. – mNm Oct 09 '17 at 05:07
  • So is the problem that the file doesn't get included or you have problems with the `header.php` file? – Rotimi Oct 09 '17 at 05:11
  • the webpage that im building is working fine, now i wanted to include a log in system with it so decided to try and code PHP. so to make it neat of course we used include header php working ok. syntax is also good not being detected by my text editor if there is something wrong ive placed the header.php file to a folder and remove it and placed it on the root directory just to be sure but still no go – mNm Oct 09 '17 at 05:18
  • Try another file with something like this as the contents: ` – Progrock Oct 09 '17 at 05:18
  • your running this on a php enabled web server? –  Oct 09 '17 at 05:21
  • Hi @Progrock ive tried what you said same result above ive created a new file named it test.php placed the php code in it saved it on the root directory with index.php same output as above it just outputs my code on the browser – mNm Oct 09 '17 at 05:23
  • @mNm, again edit your question to reflect what you have tried. Be verbose. Explain what you've tried, giving example code and describe what happened, and what you expected. – Progrock Oct 09 '17 at 07:29
  • Perhaps a duplicate: https://stackoverflow.com/questions/5121495/php-code-is-not-being-executed-instead-code-shows-on-the-page – Progrock Oct 09 '17 at 07:29

3 Answers3

1
  1. Try this syntax and pay attention to the opening tag:

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

  2. Make sure that file header.php is in the same directory as this file that you are coding and this file has an extension of .php

  3. Make sure that include is not disabled from php.ini (unlikely, unless someone deliberately did it)

Aydin4ik
  • 1,782
  • 1
  • 14
  • 19
1
  • Make sure all files have .php extension

    include('header.php');
    
  • Use include function script in the top of your php file

  • Filename must not be space

Thamaraiselvam
  • 6,961
  • 8
  • 45
  • 71
Partho Kar
  • 11
  • 3
1

Check php opening tag. it should be <?php not like this ?php

<?php
 include ("header.php");
?>
Anil Kumar Reddy
  • 102
  • 1
  • 1
  • 16