PHP Include for HTML?

前端 未结 7 2001
小蘑菇
小蘑菇 2020-12-02 23:22

I have a navigational bar, an image, and a heading that I\'ll be including in every page of my website, so I wanted to use php include to refer to this code in several pages

7条回答
  •  南方客
    南方客 (楼主)
    2020-12-02 23:48

    You can use php code in files with extension .php and only there (iff other is not defined in your server settings).

    Just rename your file *.html to *.php


    If you want to allow php code processing in files of different format, you have two options to do that:

    1) Modifying httpd.conf to allow this for all projects on your server, by adding:

    AddHandler application/x-httpd-php .htm .html
    

    2) Creating .htaccess file in your separate project top directory with:

    
        AddType application/x-httpd-php .html
    
    

    For second option you need to allow use of .htaccess files in your httpd.conf, by adding the following settings:

    AllowOverride All
    AccessFileName .htaccess
    

    *that is correct for Apache HTTP Server

提交回复
热议问题