1

Hey everyone... I'm not too familiar with PHP... but I have PHP code that basically "includes" a file if a condition exists. This PHP code is going to be pretty lengthy and I was wondering if it was possible to create a .php file, and just INCLUDE THAT in my shtml files? What the below is doing is placing the correct navigation bar in the shtml file by running a series of if/else statements in PHP. If the REQUEST_URI (the current page) is xxxxx.shtml, then include THIS navigation bar file, etc. This is working perfectly, but as you can imagine for a site that has hundreds of pages, I would have to place each page in this below "conditional server side includes"- and the disadvantage to this is if some menu items get rearranged in the navigation bars, I want to be able to just edit ONE PHP file rather than every single shtml file that includes the below script. I HAVE NO IDEA how to include the below PHP into it's own file. I assume I need to leave out the as that's specific to HTML. But aside from that, is it just as easy as copying and pasting the above into it's own PHP file?

Currently, here's what I have in every one of my shtml files (it WILL get bigger, this is to just start out):

            <!--#if expr="$REQUEST_URI = /1/"-->
        <!--#include virtual="navFiles/featuresCurrent.shtml" -->
        <!--#elif expr="$REQUEST_URI = /2/"-->
        <!--#include virtual="navFiles/videosCurrent.shtml" -->
        <!--#elif expr="$REQUEST_URI = /3/"-->
        <!--#include virtual="navFiles/aboutusCurrent.shtml" -->
        <!--#elif expr="$REQUEST_URI = /4/"-->
        <!--#include virtual="navFiles/subscribeCurrent.shtml" -->
        <!--#elif expr="$REQUEST_URI = /5/"-->
        <!--#include virtual="navFiles/toolsCurrent.shtml" -->
        <!--#elif expr="$REQUEST_URI = /6/"-->
        <!--#include virtual="navFiles/membershipCurrent.shtml" -->
        <!--#endif --> 

I want to be able to create an individual .php file that contains the above code, and instead of putting the ABOVE in my shtml pages, I would just put something like "include xxxx.php". Is this possible?

4

3 回答 3

1

Yes you put your code in a file and include that file like this:

<?php include ("path to file");?>

Have a look at include function.

于 2010-08-26T15:55:03.310 回答
1

您可以使用

auto_prepend_file = /path/to/file.php

在您的 php.ini 或 .htaccess 文件中,该文件将在每个 php 脚本之前“require_once”file.php。

于 2010-08-26T15:58:46.827 回答
0

如果您希望此脚本可用于整个应用程序,则应通过设置将其路径添加到 php.ini 中的库路径include_path = 'path\to\php\file'

如何做到这一点的例子: http ://www.cyberciti.biz/faq/how-do-i-set-php-include-path-in-php-ini-file/

于 2010-08-26T15:59:08.420 回答