Forum Moderators: coopster
How should I be pointing my links to my files within my php includes? How do you guys do it? I have found some answers but they all seem a little unnecessary - they are all these small to large php scripts. Well there has to be some way to just point at file, regardless of where it sits, and be done with it, right? Thanks again!
The content of the include file will be included internally by the server, to be a part of some other page, at the URL for that other page. Only then will the browser be able to resolve a URL from that data in the link.
Use URLs that being with / to show the full path tto the other content. It will then always resolve correctly. URLs in links are otherwise resolved by the browser using the URL for the currently viewed page as a base.
<?php include("../includes/thecode.php"); ?>
For pages in the root, this is what I use that works:
<?php include ("includes/thecode.php"); ?>
For using absolute paths I believe you'd have to use the actual Apache paths (not the same as the URI). It's easier to just use relative links, but they can't be done the same way for pages in the root as they are for pages in /directories/.
Example -
include('/var/www/domains/example.com/htdocs/include/some_file.php');
include('/include/some_file.php');
On some of the sites where I have subdomains set up I generally use absolute url's for includes. As the subdomains sit on the same server, however have different file system paths to the web root. So instead of copying the code into all of the subdomains I can use 1 set of code across all of them. This does rely on settings in php.ini that are not always available on all servers, so this may or may not work for you anyway.
<edit>
Same thing as Marcia said above.
[edited by: PHP_Chimp at 11:51 am (utc) on Mar. 26, 2008]