开发者

I have PHP code that needs to be referenced in every single shtml page, is the below possible?

开发者 https://www.devze.com 2023-01-13 10:13 出处:网络
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

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/abo开发者_StackOverflowutusCurrent.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?


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.


you can use

auto_prepend_file = /path/to/file.php

in your php.ini or .htaccess file which will "require_once" file.php before every php script.


If you want this script to be available to your entire application, you should add its path to the library path in your php.ini by setting include_path = 'path\to\php\file'

Example of how to do that: http://www.cyberciti.biz/faq/how-do-i-set-php-include-path-in-php-ini-file/

0

精彩评论

暂无评论...
验证码 换一张
取 消