Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.
got a question...how do you guys handle the url paths of links and images for included files when the 'includer file' is different from the 'included file' ...
to use a pseudo example
i have /default/test1.php
and i have /custom/test2.php
in test1.php i include test2.php with test2.php having a link to an image (image/test.jpg) /custom/images/test.jpg. The obvious solution would be to 'copy' the test.jpg over to the default/images/ but is there anyway to avoid having the same file in to different places?
The usual solution is absolute paths. If you want to get fancy, you can try to run the included file through a post-processor that munges things accordingly.
i don't know why anyone would want to use path literals, ever. when adding to sites or doing recovery or upgrade installs (yuck), path fixing is pretty much step number one.
'jshpro2's define() is good but i'd say you'd want this to be available everywhere and not have only *some* 'big' concept values like the example 'MY_PATH', available just for the instance you are fixing.
there are lots of $_SERVER variables for filenames and paths that are i think used by loads of us. why not, like 'Everah' said, define a few more constants (or even variables) that refer to the documentroot and also some other common dirs.
they can be available everywhere like $_SERVER and mean you never have to use literals.
despite fear about global vars, and modularizing scripts that depend on particular vars, surely adding and maintaining those vars has to be easier than littering your scripts with literals ...
$_SERVER variables are insecure and should not be used for anything that have any importance to you.
jshspro's suggestion, for the time being, is a good way to go. And a heads up, in PHP 5.3 there is going to be a __DIR constant introduced that will take care of all of this for you.
ok, totally clueless about this stuff, but i looked a little but what i can see is that there is a specific problem with $_SERVER['PHP_SELF'] and a couple of others (http://seancoates.com/xss-woes).
i am using $_SERVER['DOCUMENT_ROOT'] and $_SERVER['SCRIPT_FILENAME']. anyone know of problems with these? (you know there's no mention in the PHP docs of the PHP_SELF thing. they do omit things sometimes don't they?)
AFAIK , it looks like "__DIR__ == dirname(__FILE__)" which is for the current file (not the main/parent/includer), so this may not help.
Not all server variables that you see in tutorials are going to be available to you. PHP_SELF is one of them. Never rely on it being available to you. Instead consider using either the constant __FILE__ or the SCRIPT_FILENAME server var.