dresden_phoenix — 2012-09-18T00:26:26-04:00 — #1
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.
oddz — 2012-09-18T01:47:32-04:00 — #2
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.
dresden_phoenix — 2012-09-18T03:30:12-04:00 — #3
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
cups — 2012-09-18T03:57:05-04:00 — #4
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?
dresden_phoenix — 2012-09-18T05:04:46-04:00 — #5
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);
cups — 2012-09-18T06:15:14-04:00 — #6
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.
logic_earth — 2012-09-18T10:43:26-04:00 — #7
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 );
blogaddition — 2012-09-19T02:18:15-04:00 — #8
echo $SERVER['SERVERNAME']. $SERVER['PHPSELF'];
in your code that will give you the exact url of your file.