duankezong4064 2013-04-16 16:00
浏览 32
已采纳

使用php包含在html文件中

I'm having some problems on my website using some php code.
My site is mainly using html and php. Instead of repeating lots of lines of script at the top of every page, i'm just using the php include statement:

<?php include('main.php'); ?>

I have a local WAMP server and a mixture of html and php files on my site.
When I run everything locally it all runs perfectly well and the 'include' statement works.
However, when I upload everything to my site, which is hosted on goDaddy, the include statement only works inside .php files. If I use it inside a .html file it fails. It just doesn't include anything.

I have seen some posts which say that this could be resolved by using a .htaccess file. At the moment I don't have one on my site. I did try to upload one into the root directory but the only effect this had was that it displayed a 'Save As' dialog box when I clicked on a page.
I'm guessing that either my syntax is wrong or I've gone down the wrong road to resolve this.

Below is the contents of my .htaccess file. Any ideas as to how I can get the include statement to work inside .html files would be great. Thanks.

#
# Server root folder www .htaccess
# This file provides server security limiting access to the localhost only.
# Comment next four lines to deactivate. (Allows external access)
#

# Order Deny,Allow
# Deny from all
# Allow from 127.0.0.1
# Allow from ::1
AddType application/x-httpd-php .html .php .htm


# To allow execution of cgi scripts in this directory uncomment next two lines.


# AddHandler cgi-script .pl .cgi
# Options +ExecCGI +FollowSymLinks


# Activate this section to use the Private Server Feature!
# Defaults: Username - root; Password - root
# Note AuthUserFile: File path is relative to server root
# To lock server, uncomment the next 4 lines. (A name and password is required)

#AuthName "Uniform Server - Server Access"
#AuthType Basic
#AuthUserFile ../../../htpasswd/www/.htpasswd
#Require valid-user
  • 写回答

3条回答 默认 最新

  • dsdsm2016 2013-04-16 16:05
    关注

    Try using this:

    AddHandler x-httpd-php5-cgi .html
    

    See here: http://httpd.apache.org/docs/2.2/mod/mod_mime.html#addhandler

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 C# 使用DEVMOD设置打印机首选项
  • ¥15 麒麟V10 arm安装gdal
  • ¥15 想用@vueuse 把项目动态改成深色主题,localStorge里面的vueuse-color-scheme一开始就给我改成了dark,不知道什么原因(相关搜索:背景颜色)
  • ¥20 OPENVPN连接问题
  • ¥15 flask实现搜索框访问数据库
  • ¥15 mrk3399刷完安卓11后投屏调试只能显示一个设备
  • ¥100 如何用js写一个游戏云存档
  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上