Forum Moderators: phranque

Message Too Old, No Replies

Include File Is Not Working

         

learn4life

10:41 pm on Mar 19, 2010 (gmt 0)

10+ Year Member



I'm using the include below successfully on my site but for some reason it doesn't work on the files that I have in the cgi-bin.

<!--#include file="nav/menu.html" -->


The files in the cgi-bin is using a different menu, they are in the nav folder, when I tried to use the include above it doesn't work.

cgi-bin/Script_HTML/nav

Any idea what I should do differently.

Thanks!

JS_Harris

1:11 am on Mar 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The code you posted is "commented out" and will be ignored during processing.

try this instead

<?php include("cgi-bin/Script_HTML/nav/menu.html"); ?>

Using <!-- and --> around a line of code will stop it from being processed.

If the "menu.html" file contains additional php code I suggest renaming it to "menu.php" so that it works properly when included.

lammert

1:29 am on Mar 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The code is not commented out and is not in PHP. These are server side includes in the SSI syntax and they need to be between comment lines. There are two type of SSI include versions. One is with the file parameter and the other with the virtual parameter. The difference is the starting point of the search path to find the include file. The file parameter works with file system paths and starts counting in the root directory of the server. The virtual parameter uses the website root directory as reference.

In this case I would advice to use the virtual parameter, because you seem to be referencing relative to the URLs in the website structure.

<!--#include virtual="/cgi-bin/Script_HTML/nav/menu.html" -->

learn4life

9:35 pm on Mar 20, 2010 (gmt 0)

10+ Year Member



Thanks Guys but I'm still scratching my head as to why this isn't working.

I tried this: <!--#include virtual="/cgi-bin/Script_HTML/nav/menu.html" --> but it still doesn't display. I even tried the full path just to make sure but no luck, eg: <!--#include virtual="http://www.mywebsite.com/cgi-bin/Script_HTML/nav/menu.html" -->

The pages in the cgi-bin have pearl codes so I'm wondering if that's what's causing the problem or maybe I have to change/add something to the .htaccess file? This is what's in the file:

AddType text/html .shtml .shtm .htm .html
AddHandler server-parsed .shtml .shtm .htm .html
Options Indexes FollowSymLinks Includes

tangor

11:41 pm on Mar 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If your include file contains more perl coding it might not be executing. Try an ordinary file include first. See if that works (ie, a table menu for a test). On one shared hosting site I couldn't get includes to work until using the following:

Options SymLinksIfOwnerMatch Includes

phranque

10:21 am on Mar 21, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



if your include file is a CGI script (perl) it absolutely must use the include virtual syntax.
in this case you will probably also have to make sure you have configured a cgi handler for that context (/cgi-bin/ directory) and filetype, such as:
AddHandler cgi-script .cgi

learn4life

1:05 pm on Mar 22, 2010 (gmt 0)

10+ Year Member



I sorry to bother you all but it's still not working so I thought I'd discribe as much as possible how the files are set-up and explain the type of files. Hopefully this will help you so that you can help me.

So the files are in this folder:
/public_html/mywebsite.com/cgi-bin/Script_HTML/

In the Script_HTML folder is a nav folder which has the header, footer and menu.html files. It's ONLY html that are in these files, no coding.

Below are examples of some of the pages that I want the include to display on. These pages have codes in them sch as ($greeting $fname $lname, etc...)
- display_login.html
- login_successful.html

My .htaccess file is here: /public_html/mywebsite.com/. In the .htaccess file is this:
AddType text/html .shtml .shtm .htm .html
AddHandler server-parsed .shtml .shtm .htm .html
AddHandler cgi-script .cgi
Options Indexes FollowSymLinks Includes

My include code looks like this:
<!--#include virtual="/cgi-bin/Script_HTML/nav/menu.html" -->

Could it be that the cgi-bin won't allow access? Even when I place the nav folder outside of the cgi-bin, it still doesn't work.

Thanks in advance for your help!

phranque

5:48 pm on Mar 22, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



NOTE:
the virtual attribute "should specify a URL relative to the document being served" [httpd.apache.org].
also, i'm guessing if your server is configured with a ScriptAlias Directive [httpd.apache.org] that may affect "include virtual".

i would try moving the nav directory out from under the /cgi-bin/ directory and change your include to refer to it there and see if that solves the problem.

learn4life

2:59 pm on Mar 24, 2010 (gmt 0)

10+ Year Member



Oh boy this is challenging....

I moved the nav folder outside of the cgi-bin here:
mysite.com/account-nav

I tried several variations and it still doesn't work. Is it that the include won't work with files in the cgi-bin 'cause this is just weird. I tried these:

<!--#include virtual="/account-nav/header.html" -->
<!--#include virtual="account-nav/header.html" -->
<!--#include file="/account-nav/header.html" -->
<!--#include file="account-nav/header.html" -->

The files that I'm add the include to are here:
mysite.com/cgi-bin/Script_HTML/display_account_create.html

Any other suggestions? I really would prefer not to do this manually.

icedowl

4:35 pm on Mar 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I just took a look at how I used to do this. From what I see, you might simply need to add a period (".") just before the first "/" as follows:

<!--#include file="./account-nav/header.html" -->

I also had only the following in my .htaccess file:

#========================================================
# added to allow using SSI on HTML pages:
AddType text/html .html
AddHandler server-parsed .html
#
#========================================================

rocknbil

8:04 pm on Mar 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



As a big fan of SSI ("right tool for the job" in many cases) I've been watching . . . couple comments:

If your include file contains more perl coding it might not be executing.


Correct, however, if the SSI's are working, you would get "[an error has occurred processing this directive]" when either the perl scripts are broken **OR** possibly you cannot "get" regular files from the cgi-bin, it's set to only execute. Which tells me, the SSI's are broken.

This,

AddType text/html .shtml .shtm .htm .html
AddHandler server-parsed .shtml .shtm .htm .html
Options Indexes FollowSymLinks Includes

Says it should work. Did you add this or was it already present on the domain?

So first determine if you can get **any** SSI's to work. Take this,

<html>
<head>TEST</head>
<body>
<h1>SSI test</h1>
<!--#include file="test.txt" -->
</body>
</html>

Put it in a file, name it test.shtml I know your .htaccess says it should parse .html . . . just go with it.

Take this

<p>If you can read this, SSI's are working</p>

put it in test.txt.

Upload both to the domain root. Does it work?

Problems like this are what drive people to PHP out of frustration . . . stick with it. :-)

learn4life

8:57 pm on Mar 24, 2010 (gmt 0)

10+ Year Member



Hi rocknbil,

1. My include file does not include any perl coding, only HTML

2. I add this to my .htaccess file
AddType text/html .shtml .shtm .htm .html
AddHandler server-parsed .shtml .shtm .htm .html
Options Indexes FollowSymLinks Includes

3. I have pages outside of the cgi-bin that have includes in them and they are working fine.

I've Googled but still can't find a fix. Still scratching my head...

Thanks!

lammert

11:06 pm on Mar 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Sometimes instructions in the .htaccess are totally ignored, or only a subset of the instructions is allowed. It depends on the global AllowOverride [httpd.apache.org] setting in httpd.conf of the Apache server.

phranque

4:39 am on Mar 25, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I moved the nav folder outside of the cgi-bin here:
mysite.com/account-nav

The files that I'm add the include to are here:
mysite.com/cgi-bin/Script_HTML/display_account_create.html


the virtual attribute "should specify a URL relative to the document being served"


so where is the document being served?
is it in the document root directory?
or is the requested document /cgi-bin/Script_HTML/display_account_create.html ?

tangor

4:42 am on Mar 25, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



3. I have pages outside of the cgi-bin that have includes in them and they are working fine.

This seems key (I never serve any thing FROM my cgi-bin). Check all paths, and look for typos... can't tell you how many times fat fingers has been the problem. :)