23 Replies Latest reply on May 7, 2014 3:06 PM by Ken Binney

    How do I 'include' a header.php file within my website ?

    loveAndPeace Level 1

      Hi and Thanks. I would like to use a header.php file so that the exact same information appears at the top of every page within my website.

       

      I have a site.

      I have folders inside the site

      folder: images

      folder:css:

      misc files such as: index.html and header.php.

       

      head.php

      <!doctype html>

      <html>

      <head>

      <meta charset="UTF-8">

      <title>Testing

      </title>

      </head>

      <body>

      <div id = header id="header" class="fluid">

              <h1>Web Development by myFirstName</h1></div> 

      </body>

      </html>

       

      QUESTION.

      Where do I specifically 'include' the below code within the index.html ?

      <?php include 'header.php';  ?>

        • 1. Re: How do I 'include' a header.php file within my website ?
          Jon Fritz II Adobe Community Professional & MVP

          You place it wherever you want the html from the header.php file to insert itself in your code.

           

          Be sure to change the extension of your .html pages to .php or your server won't process the include by default.

           

          You can change the extension from .html to .php in your Files window when you have your site definition open and DW will update all the links.

          1 person found this helpful
          • 2. Re: How do I 'include' a header.php file within my website ?
            Nancy OShea Adobe Community Professional & MVP

            On most shared servers, php includes will only work inside .php parent pages.  So you will need to rename index.html to index.php.

             

            Depending on what your header.php file contains, you insert the include statement where that content needs to go in your parent page.  Most likely, below the opening <body> tag.

             

            It's also worth mentioning that php includes cannot be viewed locally unless you have installed on your system and defined in DW a local testing server like Wamp, Xampp or Mamp.

             

             

            Nancy O.

            1 person found this helpful
            • 3. Re: How do I 'include' a header.php file within my website ?
              Ken Binney Adobe Community Professional & MVP

              In exactly the same place in your page code where you want the code content to appear in your page code.

               

              View  the source of this page and note the "comment" entries to see where the include code was entered and has now been rendered.

              http://www.peattiecapital.com

               

              The original page code is this (before the include has been processed by the server)

               

              <!-- HEADER INCLUDE -->

                 <?php require_once("PCheader.inc"); ?>

                 <!-- END HEADER INCLUDE -->

               

              While the "Comments" are not required, I use them for when I look at the processed source code from a browser

              • 4. Re: How do I 'include' a header.php file within my website ?
                bregent Most Valuable Participant

                >misc files such as: index.html and header.php.

                 

                To clarify what others have said, your parent page (index.html in this case) needs to have an extension that the server will parse for includes. If you are using php, then the obvious choice is to change it to index.php. However, if this is an established site with good search ranking, you might want to consider other options. For the included page, the extension can be anything.

                1 person found this helpful
                • 5. Re: How do I 'include' a header.php file within my website ?
                  loveAndPeace Level 1

                  I really appreciate forums

                  I hope that I am explaining this correctly.

                  I feel like I have sorted out so much and now I am stuck on some of these fundamentals.

                  Starting yet another tutorial for this issue at least - is counterproductive at this point.

                   

                  Background:I have been coding in php using the netbeans IDE.

                  I have apache mysql and phpmyadmin installed on my mac.  MAMP.

                  Now I want to create a website using Dreamweaver.

                   

                  Objective:

                  With navigation, I would like the user of my website to click to go to some of the webpages where there will be examples of my php applications.

                   

                  Questions.

                  The page of entry is always index.html - yes ?
                  One of you has suggested that I need to change it to index.php.  I do not understand this.

                  Within Dreamweaver and everywhere, I thought it is always index.html.

                   

                  Dreamweaver. I am still a bit confused.  I am choosing fluidGridLayout for the platform so that I that I have auto reflow working on all 3 types of devices.  It works - the reflow.

                   

                  Specifics of my site so far:

                  The index.html shows several images that I created with illustrator and if you click on the image, it redirects you to another page.  It works = the navigation to the other webpage.

                   

                  Each of those images are within their own <div>

                  Here is an example:

                  div id="Square" class="fluid"><a href="images/Square.jpg"><img src="images/Square.jpg"  alt=""/></a></div>

                   

                  I want to have the same header on each page.

                   

                  Here is part of the code.  It still does NOT work. 

                  index.html

                  <script src="file:///Library/WebServer/Documents/webDevelopDWsites/respond.min.js"></script>

                  </head>

                  <body>

                  <?php include 'header.php';  ?>

                      <div class="gridContainer clearfix">

                        <div id="div1" class="fluid">

                                  <header id="header" class="fluid">Web Development by firstName</header>

                          <div id="Square" class="fluid"><a href="images/Square.jpg"><img src="images/Square.jpg"  alt=""/></a></div>

                   

                  header.php

                  <!doctype html>

                  <html>

                  <head>

                  <meta charset="UTF-8">

                  <title>headerForFourSquares

                  </title>

                  </head>

                  <body>

                  <div id = header id="header" class="fluid">

                          <h1>Web Development by firstName</h1></div>    

                  </body>

                  </html>

                   

                  I am missing something conceptually.  Thanks ahead of time for the clarifications.

                   

                  Oh And ultimately I will have a different image/log that is also in the header of every page so that a user can click on to return to the home page.

                  • 6. Re: How do I 'include' a header.php file within my website ?
                    loveAndPeace Level 1

                    Okay.  I am going to change the extension now.

                    • 7. Re: How do I 'include' a header.php file within my website ?
                      loveAndPeace Level 1

                      Thanks. I am unable to view source on the ipad.

                      • 8. Re: How do I 'include' a header.php file within my website ?
                        bregent Most Valuable Participant

                        OK good. And to answer your question:

                         

                        >Questions.

                        >The page of entry is always index.html - yes ?

                         

                        No. The default page can be set to anything. In your server configuration files you can create a list of default page it will search for.

                        So if your site has both index.html and index.php, it will serve whatever is defined first in that list.

                        • 9. Re: How do I 'include' a header.php file within my website ?
                          loveAndPeace Level 1

                          Please respond and explain.

                          By changing the extension these things happened.

                           

                          Save as: index.php resulted in this popup box.

                          It required me to type in some server type options.

                          I choose (not certain of exact fieldNames)

                          name: localhost

                          server connection: local/network

                          browse to:  I navigated to Library/Webserver/Documents  (standard for mac users)

                          url:  left blank.

                           

                          Now Error Messages.

                          Files will be updated on the testing server.  Yes  No.

                          I tried both and each time it the browser says:

                          The requested URL /index.php was not found on this server.

                           

                          The this came up.

                          Started: 5/6/14 1:26 PM

                          index.php - error occurred - An error occurred - cannot put index.php.  Access is denied.  You do not have sufficient access privileges.

                          File activity incomplete. 1 file(s) or folder(s) were not completed.

                          Files with errors: 1

                          index.php

                          Finished: 5/6/14 1:26 PM

                          thanks again.

                          • 10. Re: How do I 'include' a header.php file within my website ?
                            John Waller Adobe Community Professional & MVP

                            loveAndPeace wrote:

                             

                            Thanks. I am unable to view source on the ipad.

                            Many workarounds available online

                            How to View Website Source Codes on iPad / iPhone [Quicktip]

                            • 11. Re: How do I 'include' a header.php file within my website ?
                              loveAndPeace Level 1

                              I do appreciate your help.  I am not a novice - just stuck

                               

                              Regarding my last post....  I clicked on 'manage sites' and reverted.

                               

                              As I mentioned  saving as index.php did not work at all. 

                              As a matter of fact, the only code that showed up in Design view is WebDevelopment by firstName.

                               

                              It must have something to do with my server settings for this 'site' and possible you can decifer it from below.  I don't get it.  The site launches with the index.html.

                               

                              paraphrased:

                              It said 'related files may only be used if discovered by the server'.  I clicked 'discover'.

                              It said  ' dynamically related files cannot be discovered because a testing server is not defined (option- click setup).

                               

                              Setup brings me back to the longer email before this where I had to type in an browse to things and which lead to the 'server not found' error.

                              • 12. Re: How do I 'include' a header.php file within my website ?
                                Jon Fritz II Adobe Community Professional & MVP

                                Have you installed a local server on your computer like XAMPP?

                                 

                                If not, php won't work correctly in DW, since there's no server in the program to process it.

                                • 13. Re: How do I 'include' a header.php file within my website ?
                                  loveAndPeace Level 1

                                  Yes.  I have mamp: mac, apache mysql phpMyAdmin installed.

                                  I have been writing code in php using Netbeans IDE - successfully.

                                  My fault for sloppy explanation.  Below is the screenshot.

                                  I bet now someone can straighten me out.  Thanks again,

                                   

                                  My project is to create a website using Dreamweaver.

                                  I want the user to navigate around.

                                  I want to demonstrate that I am able to write php code and if they land on certain pages this will be evident.

                                   

                                  Crazy that I am so stuck.   

                                   

                                  I am confused conceptually.

                                  Why does the index.html launch to the browser just fine and then I get that pop up regarding server setup when I launch the index.php.

                                   

                                   

                                  By the way, the last message actually said that I was trying to launch header.php from netbeans.

                                  That would be a completely different file.

                                  Sorry this is confusing to explain but I think that it is getting a little clearer.

                                   

                                  If you want to replicate what is happening, in

                                  Dreamweaver > Site >New Site >

                                  click on servers (in left frame) >

                                  click the + sign.

                                   

                                  Here is the .png. I do not know what to fill in here that works.

                                  I tried this:

                                  Server Name: local host

                                  Connection using:  local/network

                                  Server Folder:  I navigated to Library/WebServer/Documents  (where my dreamweaver files live)

                                  URL: left blank and tried using  localhost

                                  siteSetupServerSettings.png

                                  • 14. Re: How do I 'include' a header.php file within my website ?
                                    Nancy OShea Adobe Community Professional & MVP

                                    When developing PHP sites, I always put my local site inside the testing server's default site folder.  On Wamp, that is the www folder.  In Xampp it is the htdocs folder.  That way, when you save files in DW, they are automatically saved on the testing server.  See screenshots.

                                    CS6-testingServer1.jpg

                                    Advanced Tab:

                                    CS6-testing-server-advanced.jpg

                                     

                                    Final screen:

                                    CS6-testingServerFinalScreen.jpg

                                     

                                    Nancy O.

                                    • 15. Re: How do I 'include' a header.php file within my website ?
                                      loveAndPeace Level 1

                                      Hi Nancy and Thanks for sticking with me.

                                      PROGRESS.  Questions at end

                                      browserOutputIndexPHP

                                      browserOutput.png

                                      settings. site.

                                      siteSettings1.png

                                      settings. server.siteSettings2.png

                                      settings. advanced.

                                      siteSettingsAdvanced.png

                                      troubleshooting1.

                                      BUT when I VIEW the  index.html  file in firefox/safari  i DO get the page in the BROWSER -

                                      BUT  w/o the correct format

                                      - my 4 images are VERTICAL one atop the other rather than 2 x 2 ,

                                      and i get this NEW error:

                                       

                                      error begin.

                                      Started: 5/6/14 5:33 PM

                                      index.html - error occurred - An error occurred - cannot put index.html.  Access is denied.  You do not have sufficient access privileges.

                                      File activity incomplete. 1 file(s) or folder(s) were not completed.

                                      Files with errors: 1

                                      index.html

                                      Finished: 5/6/14 5:33 PM

                                      error end.

                                       

                                      QUESTION.  Why the above error ? 

                                      I did not have a privileges error before.

                                       

                                      troubleshooting2.

                                      these next 2 description toggle back and forth.

                                      subsequently I THEN went back and tested/launched index.php (preview in firefox/safari)

                                      i get

                                      'Server not found  Firefox can't find the server at www.localhost.com'

                                      and the following.  I click yes to both.

                                      errorTestingWillUpdate.png

                                      includeDependentFiles.png

                                       

                                       

                                      QUESTION.  I do not get it.

                                      You have been so clear so far.  Can you explain this to me ?

                                       

                                      QUESTION.

                                      How do I test this website ?

                                       

                                      Launching index.php ONLY gives me the header information as shown in the first .png

                                      which is great but the other toggling errors....  ????

                                      Thanks again. 

                                      • 16. Re: How do I 'include' a header.php file within my website ?
                                        Nancy OShea Adobe Community Professional & MVP

                                        I'm not a Mac user, but I believe the default site folder on MAMP is htdocs.  So the path to your site folder needs to be something like Mac user\mamp\htdocs\YourSiteName

                                         

                                        Unless you've configured your php.ini file to parse .html pages, you really need to use .php file extensions.  That's probably why you're getting errors when you try to preview index.html in your local browser.

                                         

                                         

                                        Nancy O.

                                        • 17. Re: How do I 'include' a header.php file within my website ?
                                          loveAndPeace Level 1

                                          Thanks again Nancy.  I had to read the entire php.ini to see what might be applicable.

                                          Not sure but here is some of it just in case something is obvious to you but not to me.

                                          php.ini below

                                          Data Handling ;

                                          ;;;;;;;;;;;;;;;;;

                                           

                                          ; The separator used in PHP generated URLs to separate arguments.

                                          ; PHP's default setting is "&".

                                          ; http://php.net/arg-separator.output

                                          ; Example:

                                          ;arg_separator.output = "&amp;"

                                           

                                          ; List of separator(s) used by PHP to parse input URLs into variables.

                                          ; PHP's default setting is "&".

                                          ; NOTE: Every character in this directive is considered as separator!

                                          ; http://php.net/arg-separator.input

                                          ; Example:

                                          ;arg_separator.input = ";&"

                                          end of excerpt

                                           

                                          begin of execerpt

                                          ; UNIX: "/path1:/path2"

                                          include_path = ".:/php/includes"

                                          ;

                                          ; Windows: "\path1;\path2"

                                          ;include_path = ".;c:\php\includes"

                                          ;

                                          ; PHP's default setting for include_path is ".;/path/to/php/pear"

                                          ; http://php.net/include-path

                                           

                                          ; The root of the PHP pages, used only if nonempty.

                                          ; if PHP was not compiled with FORCE_REDIRECT, you SHOULD set doc_root

                                          ; if you are running php as a CGI under any web server (other than IIS)

                                          ; see documentation for security issues.  The alternate is to use the

                                          ; cgi.force_redirect configuration below

                                          ; http://php.net/doc-root

                                          doc_root =

                                           

                                          ; The directory under which PHP opens the script using /~username used only

                                          ; if nonempty.

                                          ; http://php.net/user-dir

                                          user_dir =

                                           

                                          ; Directory in which the loadable extensions (modules) reside.

                                          ; http://php.net/extension-dir

                                          ; extension_dir = "./"

                                          ; On windows:

                                          ; extension_dir = "ext"

                                           

                                          end of excerpt of php.ini

                                          • 18. Re: How do I 'include' a header.php file within my website ?
                                            Nancy OShea Adobe Community Professional & MVP

                                            Actually, now that I think about it, this is an Apache setting.  So you need to create an .htaccess file at site root level.

                                            https://encodable.com/parse_html_files_as_php/

                                             

                                             

                                            Nancy O.

                                            1 person found this helpful
                                            • 19. Re: How do I 'include' a header.php file within my website ?
                                              loveAndPeace Level 1

                                              Hi again. Sorry that I have not been on this forum to reply. I have been working on things all day.

                                              Alot of time to sort out when I should be using index.html and when index.php.

                                              Another thought Question comes to mind - having to do specifically with Dreamweaver.

                                              I wanted to use Dreamweaver to take advantage of the fluid-grid-layout function so that may site will auto-flow onto the 3 different categories of devices.  It was sort of a main objective and I got side tracked with the fundamentals that I had to straighten out in my head

                                              F-G-L is NOT  really an option.  When you choose new> you choose fluid-grid-layout

                                              OR you choose Blank and then html or php.

                                              Any feedback ?? 

                                               

                                              Back to the main issue.

                                              I have gone with the strategy of using index.php  because the files will be dynamic.

                                              I started over and created a new folder named: dwwdSite  (=DreamWeaverWebDevelopmentSite)

                                               

                                              php.ini (?)

                                              Document Root Library/WebServer/Documents

                                              so my path is: Library/WebServer/Documents/dwwdSite

                                              and copied my old files into it and then followed your screenshots to make certain that I set up the server setting correctly. 

                                               

                                              Something that I did was in the httpd.conf file  I modified the code there to add index.php  and have it listed first.

                                              <IfModule dir_module>

                                              DirectoryIndex index.php index.html

                                              <IfModule>

                                               

                                              Rather than using View With Browser Safari/Firefox

                                              within the browser i am typing localhost/dwwdSite/

                                              I sort of understand why but  cannot explain it back to you

                                              I will try.  browser's interpret html code not php code.

                                              Php is interpretted before anything is uploaded to the browser.

                                              Server side code is interpretted before client (browser-side) code.

                                              So on selects to view with browser in Dreamweaver - they are directly looking at the page in the browser before the backended code gets to process.

                                               

                                               

                                              I am STILL getting an error  'Unable to Connect'.

                                               

                                              I am posting my screenshots again.  Maybe you can spot some mistake but I used your screenshots as the template for my own. Again, I appreciate your help.

                                               

                                              siteSetting.png

                                              ServerNameAdvanceTab.png

                                              AdvancedSettingsLocalInfo.png

                                              AdvanceServerModelSqlPhp.png

                                              Really thanks.  I hope one day to be on your side of things helping people in this forum.  I do help in this world but as of yet not with coding.

                                              • 20. Re: How do I 'include' a header.php file within my website ?
                                                loveAndPeace Level 1

                                                a few typos.  wish there was an edit function in this forum. or a preview.

                                                • 21. Re: How do I 'include' a header.php file within my website ?
                                                  John Waller Adobe Community Professional & MVP

                                                  loveAndPeace wrote:

                                                   

                                                  wish there was an edit function in this forum. or a preview.

                                                  When you click on the Actions link (below the Correct Answer button), what options do you see in the dropdown menu?

                                                   

                                                  actions.png

                                                  • 22. Re: How do I 'include' a header.php file within my website ?
                                                    loveAndPeace Level 1

                                                    I see 'no options available'.

                                                    I actually did look there

                                                    Thanks for following up.

                                                    • 23. Re: How do I 'include' a header.php file within my website ?
                                                      Ken Binney Adobe Community Professional & MVP

                                                      Once a post of yours has been answered, the normal "Edit" or "Delete" options are no longer available.

                                                      Try a reply to me and then use the "Actions" button to Edit