kfordham281 Posted March 10, 2006 Share Posted March 10, 2006 I'm new to this command sorry if this is a dumb question....I looked around a bit and didn't see an answer. I'm trying to include my nav bar (navigation.php) as a php include on my website because the site is getting larger and to be able to change the nav bar only once will save me a lot of time. My problem is that I can't seen to get the include function to work on html files. I've even done a simple example and the php example worked fine but the html did not. www.cpadventures.com/test/main.php - works fine and you can see the test www.cpadventures.com/test/main.html - blank as the php include function isn't getting processsed. the files are exactly the same except for their extension. So how do I get the php include function to work inside html files? Thank You Quote Link to comment Share on other sites More sharing options...
kfordham281 Posted March 10, 2006 Author Share Posted March 10, 2006 Doh! >RemoveHandler .html .htm AddType application/x-httpd-php .php .htm .html Added it to my .htaccess file...all working now! Quote Link to comment Share on other sites More sharing options...
TCH-Tim Posted March 10, 2006 Share Posted March 10, 2006 Sometimes you just need to post the question and it will all become clear. Glad you got it working. Quote Link to comment Share on other sites More sharing options...
kfordham281 Posted March 13, 2006 Author Share Posted March 13, 2006 (edited) I've come across a different problem with php include. My nav bar is different for my website based on where in the site you are. The different files reflect the "../" that leads back to the webroot cpa_navigation.php - anything in the root of my web directory event_cpa_navigation.php - anything that is in a subfolder of the web root. When trying to link to the event_cpa_navigation.php I get the following error: Code below from: http://www.cpadventures.com/adventure24/directions2.htm >Warning: main(../phpincludes/event_cpa_navigation.php): failed to open stream: No such file or directory in /home/<username>/public_html/adventure24/directions2.htm on line 37 Warning: main(../phpincludes/event_cpa_navigation.php): failed to open stream: No such file or directory in /home/<username>/public_html/adventure24/directions2.htm on line 37 Warning: main(../phpincludes/event_cpa_navigation.php): failed to open stream: No such file or directory in /home/<username>/public_html/adventure24/directions2.htm on line 37 Warning: main(): Failed opening '../phpincludes/event_cpa_navigation.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/<username>/public_html/adventure24/directions2.htm on line 37 When using the exact same include path; only changing the name from "event_cpa_navigation.php" to cpa_navigation.php it works fine. Summary: <?php include ("../phpincludes/event_cpa_navigation.php"); ?> - Does not work <?php include ("../phpincludes/cpa_navigation.php"); ?> - Does work And yes, the event_cpa_navigation.php file IS in the location mentioned. Though it does not seem like it. Very strange! Edited March 13, 2006 by kfordham281 Quote Link to comment Share on other sites More sharing options...
abinidi Posted March 13, 2006 Share Posted March 13, 2006 I don't know the answer (sorry) but you should edit your "code" section to remove your cpanel username... Generally, you'll want to replace that with something like <UserName> or something. That way, we can still see the structure of the error message, but your cPanel username isn't compromised. For example: >Warning: main(../phpincludes/event_cpa_navigation.php): failed to open stream: No such file or directory in /home/<UserName>/public_html/adventure24/directions2.htm on line 37 Quote Link to comment Share on other sites More sharing options...
kfordham281 Posted March 13, 2006 Author Share Posted March 13, 2006 Thanks Paul; didn't notice it hiding in there. Quote Link to comment Share on other sites More sharing options...
TCH-Bruce Posted March 13, 2006 Share Posted March 13, 2006 Change them to this and they will work 100% of the time. ><?php include ("/home/cpaneluser/phpincludes/event_cpa_navigation.php"); ?> <?php include ("/home/cpaneluser/phpincludes/cpa_navigation.php"); ?> Quote Link to comment Share on other sites More sharing options...
surefire Posted March 13, 2006 Share Posted March 13, 2006 There are several ways to do what you want, but they're all basically the same: you have to have include instructions that are independent of where the file is in the site structure. Most common: @(include $_SERVER['DOCUMENT_ROOT'].'/dir/to/file.php') or die('include file one not found'); Quote Link to comment Share on other sites More sharing options...
jayson Posted March 14, 2006 Share Posted March 14, 2006 I'm new to this command sorry if this is a dumb question....I looked around a bit and didn't see an answer. I'm trying to include my nav bar (navigation.php) as a php include on my website because the site is getting go to www.jaysarahandy.com I did my site in PHP and have a navbar Quote Link to comment Share on other sites More sharing options...
deanavail Posted March 15, 2006 Share Posted March 15, 2006 you can do two ways: 1. issue include statement defining include directory each time: <?php include $_SERVER['DOCUMENT_ROOT']."/phpincludes/event_cpa_navigation.php" ; ?> 2. what happens if you decide to change servers, portability is an issue, you will have to go to wherever your include statement are at and change each one. If you have a bunch of pages you will be busy a while. Better method is to set a an includes path so if you change servers you just reset the include path once. you would need to: add .inc to the file name just so you know it is an include file (this is optional) place all your .inc include files in a library directory, set the path to this library directory as below:include_path .:/home/user/cpanelid/htdocs/cpadventures/lib/ and then call the specific include file as below:<?php include("event_cpa_navigation.inc.php") ; ?> Quote Link to comment Share on other sites More sharing options...
jayson Posted March 15, 2006 Share Posted March 15, 2006 here is a post that they did to help me out changing my site from .html to .php PHP INCLUDE Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.