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条)

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看