Is there a way for an include to store its own URL?
Using something like 'PHP_SELF','SCRIPT_NAME','REQUEST_URI' will return info pertaining to the file that includes the script ( of course) which is not what I want in this case.
I believe the FILE magical constant is what you are after. Though that is the files full path not a URL. If you must have a URL you could do some string manipulation to get only the part accessible via http.
Actually FILE was my second attempt ( I should have mentioned it, but i didnt know how to elaborate on it).
What i am trying to accomplish is figure out where the ROOT of the SITE installation is. For example: the index page for the site could be directly at mysite.com or mysite.com/guests/sites/myActualsite/
so i need a way to make a url from file, even if i dont know where my initial directory actually is
I am a wee bit confused by the question because include files are normally stored outside (ie above) the site's doc root for security reasons.
Maybe you could work out the path you need by looking at all the vars output from one of you scripts:
Perhaps explaining further about why you need to grab the url of an included file would shine a light on the exact problem you face?
No worries it is a bit confusing.
This is what I have com up with thus far, maybe it will show what i am trying to do ( actually it works!! ) but maybe there is a more graceful way to do this?
declare ('ROOT', $pb2);
define ('ROOT', $pb2);
Using define works for me.
echo "This file is at ". __FILE__ ;
echo "<hr /> ";
echo "The root is at " . ROOT ;
var_dump( $prebase );
This file is at C:\\var\\www\\html\\code\\phoenix_test.php
The root is at http://code
0 => string 'C:\\var\\www\\includes\\dresden_test.php' (length=36)
EDIT, and yes http://code is the domain name for where I test stuff on localhost.
I recommend just hard coding this stuff, easier that way then trying to be clever. The application should if ever change locations (relative to the web server's document root) and when it does it would be easy to adjust.
Btw... $SERVER['DOCUMENTROOT'] str_replace( $SERVER['DOCUMENTROOT'], DIR, $rel_path );
echo $SERVER['SERVERNAME']. $SERVER['PHPSELF'];
in your code that will give you the exact url of your file.
This topic is now closed. New replies are no longer allowed.