Forum Moderators: coopster

Message Too Old, No Replies

PHP is > my include file!

         

Khemikal

7:12 pm on Mar 23, 2004 (gmt 0)

10+ Year Member



Ok, allow me to set the stage. I've been using SSI for all my navigation for quite some time. No problemo! Well, I have two pages on a site I just completed that have php in them...the pages are .php instead of .html (just want to make sure we are all on the same...forgive the pun...page).

Anyways, on the non php pages, the include files show up fine. On the php pages, none of the navigation shows up! Grrrr. So I figured, "hey, now would be a great time to start using php for all of my navigation files". Well here is a short list of all the variations I tried with both php and includes and the end result was either the navigation still didnt show or it showed with an error like this to the right of the links: ");?>

Things I tried:

<?php include_once("topnav.htm");?>
<?php echo("<!--#include virtual="/topnav.htm"-->);?>
<?php include_once("""<!--#include virtual="/topnav.htm"-->""");?>
<?php include_once("<!--#include virtual='/topnav.htm'-->");?>
<?php include_once("/topnav.htm");?>
<?php include_once("<!--#include virtual="/sitemenu.htm"-->");?>
<?php include_once("<!--#include virtual=\"/sitemenu.htm\"-->");?>
<?php include_once("/sitemenu.htm");?>
<?php include_once("sitemenu.htm");?>
<?php include("sitemenu.htm");?>

Any suggestions? Thanks, Khem

brucec

7:17 pm on Mar 23, 2004 (gmt 0)

10+ Year Member



This happened to me and my problem was that I had the HTML headers in my PHP SSI. I removed the HTML tags and it worked fine.

Your code looks fine.

brucec

7:19 pm on Mar 23, 2004 (gmt 0)

10+ Year Member



Also, try adding the server path to the htm call. That was also another problem of mine.

Hope this helps.

jatar_k

7:32 pm on Mar 23, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



1.<?php include_once("topnav.htm");?>

- fine as long as the path is right

2.<?php echo("<!--#include virtual="/topnav.htm"-->;?>

- you didn't escape quotes and missed a set of quotes, should be
<?php echo("<!--#include virtual=\"/topnav.htm\"-->";?>

though there isn't really any point to echo'ing an SSI include, just include with php

3.<?php include_once("""<!--#include virtual="/topnav.htm"-->""");?>

uh, not totally sure what is going on here, won't work. I skipped over all the includes with includes similar to the above.

4. <?php include_once("/topnav.htm");?>
<?php include_once("/sitemenu.htm");?>
<?php include_once("sitemenu.htm");?>
<?php include("sitemenu.htm");?>

all of these seem fine but it all depends on whether the path is right.

where are topnav and sitemenu located in relation to the root of your site ie. /

Khemikal

8:33 pm on Mar 23, 2004 (gmt 0)

10+ Year Member



The two nav files sitement.htm and topnav.htm are both located in the main root of the site.

Khem

jatar_k

9:19 pm on Mar 23, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



then

<?php include "/topnav.htm";?>

and

<?php include "/sitemenu.htm";?>

Birdman

9:46 pm on Mar 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



During my trials and tribulations I have found that the safest route is to use the full system path to your include file. You can do it with PHP, or hard code it:

include("/var/www/html/topnav.htm"); //hardcoded

or

include($_SERVER["DOCUMENT_ROOT"]."/topnav.htm"); //using PHP's $_SERVER global

I imagine the second version is better because it makes the script portable(move it to any server).

jatar_k

9:51 pm on Mar 23, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



yep listen to birdman not me

I was doin too many things at once, the second one mentioned is the way to go.

my earlier post with /topnav.htm would never work. includes are based on the file system and don't care about site roots etc so you need the $_SERVER['DOCUMENT_ROOT'] to give it a clue.

sry about that

pixel_juice

11:14 pm on Mar 23, 2004 (gmt 0)

10+ Year Member



I always end up using

<? require_once $DOCUMENT_ROOT . "/directory/document";?>

I know the require will halt the page, but do you think I would be better off using include()?

Khemikal

11:23 pm on Mar 23, 2004 (gmt 0)

10+ Year Member



Ok, this is pissing me off. I tried both of Birdmans suggestions and in both instances, the include files do not show.

Khem

[edited by: jatar_k at 11:44 pm (utc) on Mar. 23, 2004]
[edit reason] just keepin it clean [/edit]

Birdman

12:03 am on Mar 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Could you post the error you get?

Khemikal

12:16 am on Mar 24, 2004 (gmt 0)

10+ Year Member



Birdman,

When I use:

<?php include("/var/www/html/topnav.htm");?>

I don't get an error. Just the topnav or the sitemenu nav don't appear at all on the site. Everything compresses together and there is no navigation, just like the file isn't being included.

Khem

Khemikal

12:25 am on Mar 24, 2004 (gmt 0)

10+ Year Member



I lied, when I use the above in a .php document, I get this error (line 68 being where the php is)

Warning: open_basedir restriction in effect. File is in wrong directory in /home/httpd/vhosts/tundrageckos.com/httpdocs/tundra-geckos-available-geckos.php on line 68

Warning: Failed opening '/var/www/html/topnav.htm' for inclusion (include_path='.:/usr/share/pear') in /home/httpd/vhosts/tundrageckos.com/httpdocs/tundra-geckos-available-geckos.php on line 68

If I add the code to a .html page, then nothing shows in the navigation.

****OK I changed the path and now it works fine on the PHP pages. Time to see if I can get this to work with the html pages***

Khem