使用php包含在html文件中 [英] Use of php Include in html files

查看:210
本文介绍了使用php包含在html文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用某些php代码的网站上遇到了一些问题.
我的网站主要使用html和php.而不是在每个页面的顶部重复很多行脚本,我只是使用php include语句:

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'); ?>

我的网站上有一个本地WAMP服务器以及html和php文件的混合体.
当我在本地运行所有内容时,它们都运行良好,并且'include'语句有效.
但是,当我将所有内容上传到托管在goDaddy上的网站时,include语句仅在.php文件中有效.如果我在.html文件中使用它,它将失败.它只是不包含任何东西.

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.

我看到一些帖子说可以通过使用.htaccess文件来解决.目前,我的网站上没有任何一个.我确实尝试将一个文件上传到根目录,但是这样做的唯一效果是,当我单击页面时它显示了另存为"对话框.
我猜想我的语法有误或者我走了错误的道路来解决这个问题.

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.

下面是我的.htaccess文件的内容.关于如何使include语句在.html文件中工作的任何想法都很棒.谢谢.

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

推荐答案

尝试使用此功能:

AddHandler x-httpd-php5-cgi .html

请参阅此处: http://httpd.apache.org/docs /2.2/mod/mod_mime.html#addhandler

这篇关于使用php包含在html文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆