Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    May 2011
    Posts
    22
    Thanks
    4
    Thanked 0 Times in 0 Posts

    PHP include code not working

    Hello.

    I am new to PHP. I am designing a website and would like to use the same header & footer throughout the site. It is my understanding I can take the header code and save it as a php file, then use a php include to pull it into each page.

    I tried the process and it didn't work. When I look at the page source I see the php statement instead of the HTML code.

    I am certain my web server has php. In order to install forum software I ran a pre-requisite check which confirm it. Also I tried running the following code:

    <?php
    phpinfo();
    ?>

    What returned was a display page showing my PHP information.

    I saved the below code as header.php
    Code:
    <div id="header">
    	<div class="pageWidth">
    		<div id="headerContent">
    			<div class="screenShot">
    				<img src="images/makati_condo_skyline.jpg" alt="Makati night view" width="960" height="212" />
    			</div> 
    		
    			<nav>
    				<ul id="nav">
    					<li class="selected"><a href=".">Home</a></li>
    					<li><a href="view.html">Photos</a></li>
    					<li><a href="rent.html">Availability & Rates</a></li>
    					<li><a href="makati.html">Makati Info</a></li>
    					<li><a href="about.html">Contact Us</a></li>
    				</ul>
    			</nav>
    		</div>
    	</div>
    </div>
    In the body of my index.html file I added the following line:

    Code:
    <?php include("header.php"); ?>
    My header did not appear, the source shows that exact line of code. Any ideas of what I am doing wrong?

  • #2
    Regular Coder
    Join Date
    May 2011
    Posts
    122
    Thanks
    23
    Thanked 0 Times in 0 Posts
    Put
    Code:
    <?php include("header.php"); ?>
    ABOVE the <html> tag.

  • #3
    New Coder
    Join Date
    May 2011
    Posts
    22
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thanks for the suggestion. That did not work.

    My View Source appears as follows when I tried:

    <!DOCTYPE HTML>
    <?php include("header.php"); ?>
    <html>
    <head>

  • #4
    Daf
    Daf is offline
    Regular Coder
    Join Date
    Feb 2005
    Location
    East Texas
    Posts
    140
    Thanks
    32
    Thanked 2 Times in 2 Posts
    In the body of my index.html file I added the following line ...
    You will need to rename your index to index.php if you use a php include I believe - give that a try.

    Your include should go where you want the header to appear ...

    Daf

  • Users who have thanked Daf for this post:

    RyanK (05-29-2011)

  • #5
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    Quote Originally Posted by RyanK View Post
    Hello.
    In the body of my index.html file I added the following line:
    Why on earth would you call you index file .html yet put php code inn it to include other .php files?

    .html = No php execution*
    .php = php execution

    *Typical server setup
    I can't really think of anything to write here now...

  • #6
    New Coder
    Join Date
    May 2011
    Posts
    22
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thank you Daf. That worked.

    @Tangoforce, I have never worked with php. I searched for a solution to include page headers & footers in a html file so the code did not have to be copied/pasted to every page. I came across this method. The instruction to change the file type from html to php was not offered.

    I have now learned that a html file can be renamed with the php extension and it will still work.

    Thanks for the help!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •