View Full Version : php includes and base href
grandpafred
October 12th, 2007, 01:23
I've only used the base href concept with ASP pages and never encountered a problem... I'm trying to help a friend of mine using PHP and can't quite figure out what's going on.
Scenario:
Most pages of the site are in the root: www.domain.com/page.php
Included items like footer/main menu etc are in:
www.domain.com/includes/mainmenu.php and since the menu items are in the root mainmenu.php is written with links like this:
a href="page.php"
He now wants to create some nested directories like this:
www.domain.com/sub/sub/page.php and use base href on that page to handle the mainmenu which I thought would work based on my having done that with ASP. However, this is not the case.... I get nasty php errors.
I set the base href to http://www.domain.com and the page has no problem with using the style sheet which is accessed by
href="/includes/page.css
BUT has a problem with the mainmenu which is trying to be accessed like this:
<?php include("/includes/mainmenu.php") ?>
I've tried putting a trailing slash / in the base href and removing the leading slash everywhere else... I've tried leaving the base href alone and adding a preceeding slash to the mainmenu links but can't get any combination to work.
I would suppose I could always suggest putting the absolute path in the mainmenu.php file but I am curious as to why the base href idea isn't working.
TIA
kirxklox
October 12th, 2007, 02:03
Have you checked for a Permissions Problem?
inimino
October 12th, 2007, 02:11
You must be careful about the distinction between filesystem paths and the path component of a URI.
Included items like footer/main menu etc are in:
www.domain.com/includes/mainmenu.php
I'm not sure this is quite right. www.domain.com/includes/mainmenu.php suggests you are thinking of this as having a URL, but this is just a file on the filesystem, included by PHP. It might be accessible at that URL, or it might not; there's no reason for it to be accessible by HTTP at all, and steps are often taken to prevent direct HTTP access to files that are intended only to be included.
and since the menu items are in the root mainmenu.php is written with links like this:
a href="page.php"
He now wants to create some nested directories like this:
www.domain.com/sub/sub/page.php and use base href on that page to handle the mainmenu which I thought would work based on my having done that with ASP. However, this is not the case.... I get nasty php errors.
There's no need for <base>, just rewrite those links as <a href="/page.php">.
I set the base href to http://www.domain.com and the page has no problem with using the style sheet which is accessed by
href="/includes/page.css"
That will work with or without <base> because the leading slash specifies that this is an absolute path.
BUT has a problem with the mainmenu which is trying to be accessed like this:
<?php include("/includes/mainmenu.php") ?>
That's because that's a filename, not a URI path component, and it's handled by PHP on the server side, not by the browser, so <base> has no effect. The filesystem knows nothing of the structure of your URI space. Unless you actually have a file at /includes/mainmenu.php on your filesystem that won't work.
I've tried putting a trailing slash / in the base href and removing the leading slash everywhere else... I've tried leaving the base href alone and adding a preceeding slash to the mainmenu links but can't get any combination to work.
Don't use <base>. The purpose of <base> is to deal with relative URIs in documents that are not served over HTTP. As long as you are serving your document over HTTP, your relative links will already be evaluated in the context of the URI of your page, and <base> buys you nothing.
Your PHP include() statements are something else altogether, you need to make sure the path is the correct filesystem path relative to the current directory on the filesystem. So you probably need to use something like:include("../includes/mainmenu.php");
I would suppose I could always suggest putting the absolute path in the mainmenu.php file but I am curious as to why the base href idea isn't working.
You should do that, the only way <base> can prevent you from needing to use absolute paths there would be if you put a URI in <base> that is different from the URI of the page, which would be incorrect.
kirxklox
October 12th, 2007, 05:35
It depends upon how he has .htaccess set and his File permissions.
william smith
April 29th, 2011, 20:27
Not entirely Jamie. I did have to pay Sprint a $200 disconnection fee in order to switch services. Once you're in a contract, you're no longer eligible for phone discounts. But if you find a line of phones where the savings are substantially more than the disconnect fee, yes, you could run a racket like that.
Steering Shaft (http://www.buyautoparts.com/steering-shaft.html)
george22
June 29th, 2011, 09:16
Thanks for sharing this information. I really like your way of expressing the opinions and sharing the information. It is good to move as chance bring new things in life, paves the way for advancement, etc. But it is well known to everyone that moving to new location with bulk of goods is not an easy task to move or shift from one place to other place because I have experienced about that and I face the problem like that. There I go to village near to my city faced that problem there.
70-643 (http://www.realtests.com/exam/70-643.htm) 642-437 (http://www.realtests.com/exam/642-437.htm) 642-631 (http://www.realtests.com/exam/642-631.htm) HP0-S28 (http://www.realtests.com/exam/HP0-S28.htm) HP2-H08 (http://www.realtests.com/exam/HP2-H08.htm) 642-642 (http://www.realtests.com/exam/642-642.htm) JN0-332 (http://www.realtests.com/exam/JN0-332.htm) 640-864 (http://www.realtests.com/exam/640-864.htm) 70-646 (http://www.realtests.com/exam/70-646.htm) 1Y0-A24 (http://www.realtests.com/exam/1Y0-A24.htm) 646-985 (http://www.realtests.com/exam/646-985.htm) 646-656 (http://www.realtests.com/exam/646-656.htm)
jhonnash
July 3rd, 2011, 19:45
Not entirely Jamie. I did have to pay Sprint a $200 disconnection fee in order to switch services. Once you're in a contract, you're no longer eligible for phone discounts. But <a href="http://gedpracticetestsonlines.com/ged-language-arts.htm">GED Language Arts</a> if you find a line of phones where the savings are substantially more than the disconnect fee, yes, you could run a racket like that. <a href="http://gedpracticetestsonlines.com/printable-ged-tests.htm">printable ged practice test</a>
NhocCuteGirl
July 4th, 2011, 01:19
Have you checked for a Permissions Problem?
__________________
Download Software (http://soft444.com)
alton100
July 4th, 2011, 14:02
I used to be more than happy to seek out this internet-site.I wanted to thanks in your time for this glorious read!! I positively enjoying each little bit of it and I have you bookmarked to check out new stuff you weblog post.
E20-322 (http://www.certkey.com/E20-322.html) \\ 650-295 (http://www.certkey.com/650-295.html) \\ HP0-J51 (http://www.certkey.com/HP0-J51.html) \\ 646-656 (http://www.certkey.com/646-656.html) \\ PMI-002 (http://www.certkey.com/PMI-002.html) \\ HP0-Y31 (http://www.certkey.com/HP0-Y31.html) \\ 156-915.71 (http://www.certkey.com/156-915.71.html) \\ 642-681 (http://www.certkey.com/642-681.html) \\ 642-971 (http://www.certkey.com/642-971.html) \\ 70-682 (http://www.certkey.com/70-682.html) \\ 642-631 (http://www.certkey.com/642-631.html)
mathew4512
July 18th, 2011, 09:03
Thanks for sharing this information. I really like your way of expressing the opinions and sharing the information. It is good to move as chance bring new things in life, paves the way for advancement, etc. But it is well known to everyone that moving to new location with bulk of goods is not an easy task to move or shift from one place to other place because I have experienced about that and I face the problem like that. There I go to village near to my city faced that problem there.
1Y0-A19 (http://www.test-king.com/exams/1Y0-A19.htm) | 642-165 (http://www.test-king.com/exams/642-165.htm) | 642-982 (http://www.test-king.com/exams/642-982.htm) | PK0-003 (http://www.test-king.com/exams/PK0-003.htm) | 642-741 (http://www.test-king.com/exams/642-741.htm) | 642-067 (http://www.test-king.com/exams/642-067.htm) | 642-681 (http://www.test-king.com/exams/642-681.htm) | 000-153 (http://www.test-king.com/exams/000-153.htm) |
clark40
July 25th, 2011, 13:00
I just love your blog.Thanks for posting it. it have something that someone comeback again….there is a lot of useful information a person can get from here…I must say,well done.A good blog with great discussion and a good users,which contribute in the blog..Your blog keeps getting better and better! Your older articles are not as good as newer ones you have a lot more creativity and originality now keep it up!pass4sure 70-643 (http://www.thepass4sure.info/70-643-test.html) | pass4sure 70-646 (http://www.thepass4sure.info/70-646-test.html) | pass4sure 70-646 (http://www.thepass4sure.info/70-646-test.html) | pass4sure 70-647 (http://www.thepass4sure.info/70-647-test.html) \ pass4sure 70-648 (http://www.thepass4sure.info/70-648-test.html) | pass4sure 70-649 (http://www.thepass4sure.info/70-648-test.html) | pass4sure 70-652 (http://www.thepass4sure.info/70-652-test.html) | pass4sure 70-653 (http://www.thepass4sure.info/70-653-test.html)
albertpaul68
August 1st, 2011, 07:25
I am speechless. This is a fantastic site and very engaging too. Excellent work! That’s not really much coming from an amateur publisher like me, but it’s all I could think after enjoying your posts. Not like other site. You really know what you’re talking about too. So much that you made me want to explore more. Your blog has become a stepping stone for me, my friend. Thanks for the detailed journey. I really enjoyed the posts that I have read so far
testking (http://www.mytestkings.info) , test king (http://www.mytestkings.info) , testkings (http://www.mytestkings.info) , ccie (http://www.mytestkings.info/CCIE-notes.html) , ccna (http://www.mytestkings.info/CCNA-notes.html) , ccnp (http://www.mytestkings.info/CCNP-notes.html) , ccvp (http://www.mytestkings.info/CCVP-notes.html) , a+ certification (http://www.mytestkings.info/A-plus-notes.html) , mcp (http://www.mytestkings.info/MCP-notes.html) , pmp (http://www.mytestkings.info/Project-Management-Professional-notes.html)
george22
September 17th, 2011, 09:31
This is just a short e-mail to congratulate all you wonderful people at hostexcellence. I applied last night just after 9pm for a option C package and a domain registration. I am glad to say that all was done this morning and i have already uploaded the construction page. This is now the 6th or 7th domain I have registered with hostexcellence and it will definitely not be the last. Thanks again for the great service and keep up the good work350-029 exam dumps (http://www.newbraindumps.net/350-029-pdf.html) 350-030 brain dumps (http://www.newbraindumps.net/350-030-pdf.html) latest 350-040 dumps (http://www.newbraindumps.net/350-040-pdf.html) dumps 350-050 (http://www.newbraindumps.net/350-050-pdf.html) 352-001 exam dumps (http://www.newbraindumps.net/352-001-pdf.html) 640-553 latest dumps (http://www.newbraindumps.net/640-553-pdf.html) 640-721 brain dumps (http://www.newbraindumps.net/640-721-pdf.html) 640-802 braindumps (http://www.newbraindumps.net/640-802-pdf.html)
samstonz
September 22nd, 2011, 14:22
Thanks so much for this! I have not been this thrilled by a blog post for quite some time! You’ve got it, whatever that means in blogging. Anyway, You’re definitely someone that has something to say that people should hear. Keep up the wonderful job. Keep on inspiring the people!very useful info for me.Because i'm new in blogging and i'm need good tutorial like your post. 646-230 free dumps (http://www.braindumpsonline.com/646-230-dumps.html)/dumps for 646-364 (http://www.braindumpsonline.com/646-364-dumps.html)/646-656 free dumps (http://www.braindumpsonline.com/646-656-dumps.html)/646-671 brain dumps (http://www.braindumpsonline.com/646-671-dumps.html)/dumps for 646-985 (http://www.braindumpsonline.com/646-985-dumps.html)/650-177 free dumps (http://www.braindumpsonline.com/650-177-dumps.html)/650-195 exam dumps (http://www.braindumpsonline.com/650-195-dumps.html)/650-251 dumps (http://www.braindumpsonline.com/650-251-dumps.html)
vBulletin® v3.6.8, Copyright ©2000-2012, Jelsoft Enterprises Ltd.