Php Include

windows

Guest
I'm new to this command sorry if this is a dumb question....I looked around a bit and didn't see an answer. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/wallbash.gif" style="vertical-align:middle" emoid=":wallbash:" border="0" alt="wallbash.gif" /> <br /><br />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.<br /><br />www.cpadventures.com/test/main.php - works fine and you can see the test<br /><br />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.<br /><br />So how do I get the php include function to work inside html files?<br /><br />Thank You<!--content-->
Doh!<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->RemoveHandler .html .htm<br />AddType application/x-httpd-php .php .htm .html<!--c2--></div><!--ec2--><br /><br />Added it to my .htaccess file...all working now!<!--content-->
Sometimes you just need to post the question and it will all become clear. Glad you got it working.<!--content-->
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<br /><br />cpa_navigation.php - anything in the root of my web directory<br />event_cpa_navigation.php - anything that is in a subfolder of the web root.<br /><br />When trying to link to the event_cpa_navigation.php I get the following error:<br /><br />Code below from: <a href="http://www.cpadventures.com/adventure24/directions2.htm" target="_blank">http://www.cpadventures.com/adventure24/directions2.htm</a><br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->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<br /><br />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<br /><br />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<br /><br />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<!--c2--></div><!--ec2--><br /><br />When using the exact same include path; only changing the name from "event_cpa_navigation.php" to cpa_navigation.php it works fine.<br /><br />Summary:<br /><?php include ("../phpincludes/event_cpa_navigation.php"); ?> - Does not work<br /><?php include ("../phpincludes/cpa_navigation.php"); ?> - Does work<br /><br />And yes, the event_cpa_navigation.php file IS in the location mentioned. Though it does not seem like it. Very strange!<!--content-->
I don't know the answer (sorry) but you should edit your "code" section to remove your cpanel username... <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> 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.<br /><br />For example:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->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<!--c2--></div><!--ec2--><!--content-->
Thanks Paul; didn't notice it hiding in there.<!--content-->
Change them to this and they will work 100% of the time.<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><?php include ("/home/cpaneluser/phpincludes/event_cpa_navigation.php"); ?> <br /><?php include ("/home/cpaneluser/phpincludes/cpa_navigation.php"); ?><!--c2--></div><!--ec2--><!--content-->
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.<br /><br />Most common:<br /><br />@(include $_SERVER['DOCUMENT_ROOT'].'/dir/to/file.php') or die('include file one not found');<!--content-->
<!--quoteo(post=169172:date=Mar 10 2006, 03:05 PM:name=kfordham281)--><div class='quotetop'>QUOTE(kfordham281 @ Mar 10 2006, 03:05 PM) <a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=169172"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><div class='quotemain'><!--quotec-->I'm new to this command sorry if this is a dumb question....I looked around a bit and didn't see an answer. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/wallbash.gif" style="vertical-align:middle" emoid=":wallbash:" border="0" alt="wallbash.gif" /> <br /><br />I'm trying to include my nav bar (navigation.php) as a php include on my website because the site is getting<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />go to <!-- w --><a class="postlink" href="http://www.jaysarahandy.com">www.jaysarahandy.com</a><!-- w --><br /><br />I did my site in PHP and have a navbar<!--content-->
you can do two ways:<br /><br />1. issue include statement defining include directory each time:<br /><?php include $_SERVER['DOCUMENT_ROOT']."/phpincludes/event_cpa_navigation.php" ; ?><br /><br />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:<ol type='1'><li>add .inc to the file name just so you know it is an include file (this is optional) </li><li>place all your .inc include files in a library directory, </li><li>set the path to this library directory as below:<br />include_path .:/home/user/cpanelid/htdocs/cpadventures/lib/</li><li>and then call the specific include file as below:<br /><?php include("event_cpa_navigation.inc.php") ; ?></li></ol><!--content-->
here is a post that they did to help me out changing my site from .html to .php<br /><br /><a href="http://www.totalchoicehosting.com/forums/index.php?s=&showtopic=26301&view=findpost&p=167871" target="_blank">PHP INCLUDE</a><!--content-->
 
Back
Top