PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
benburgess
Forum Newbie
Posts: 3 Joined: Thu Jan 08, 2009 7:18 am
Post
by benburgess » Thu Jan 08, 2009 7:25 am
Hey folks.
I'm having some trouble with the following snippet. It works fine on my machine but on some machines it doesn't work.
I've pinned the issue. On some machines the "__FILE__" output includes a ".peep" directory in the path that isn't in the "DOCUMENT_ROOT" readout.
Code: Select all
echo dirname(__FILE__);
output:
/home/.peep/user/domain.com/test/
Code: Select all
echo $_SERVER['DOCUMENT_ROOT'];
output:
/home/user/domain.com
This is the code:
Code: Select all
$sq_this_site = substr(__FILE__, strlen($_SERVER['DOCUMENT_ROOT']));
$sq_this_dir = dirname(str_replace('\\', '/', $sq_this_site));
$url_protoc = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https://' : 'http://';
$sq_this_sq = $url_protoc.$_SERVER['HTTP_HOST'].'/'.$sq_this_dir;
$sq_this_site = $sq_this_sq.'/?uk='.$sq_unique_key;
$sq_initial_query = $sq_domain.'?cb='.urlencode($sq_this_site);
?>
<link rel="stylesheet" href="<?php echo $sq_this_sq; ?>/cssdocument.css" type="text/css" />
<script src="<?php echo $sq_this_sq; ?>/script1.js" type="text/javascript"></script>
<script src="<?php echo $sq_this_sq; ?>/script2.js" type="text/javascript"></script>
<script src="<?php echo $sq_initial_query; ?>" type="text/javascript"></script>
Last edited by
benburgess on Thu Jan 08, 2009 11:00 am, edited 2 times in total.
jaoudestudios
DevNet Resident
Posts: 1483 Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey
Post
by jaoudestudios » Thu Jan 08, 2009 8:59 am
$_SERVER['DOCUMENT_ROOT'];
Return the location of the script, on different servers it will be in different places depending on the server setup.
benburgess
Forum Newbie
Posts: 3 Joined: Thu Jan 08, 2009 7:18 am
Post
by benburgess » Thu Jan 08, 2009 10:54 am
I'm looking for a way to get the web directory of the currently executing file. $_SERVER['
DOCUMENT_ROOT']; always results with the file that is including the above file. I want the returned root to be that of the file above no matter where it is being included.
Also, web root not document root because this is for <Script> tags and other such references that are in the HTML layer.
benburgess
Forum Newbie
Posts: 3 Joined: Thu Jan 08, 2009 7:18 am
Post
by benburgess » Thu Jan 08, 2009 10:59 am
jaoudestudios wrote: $_SERVER['DOCUMENT_ROOT'];
Return the location of the script, on different servers it will be in different places depending on the server setup.
Would return /home/user/domain.com/test/.... a file path containing directories outside of the web root!
I need to convert the __FILE__ readout to
http://domain.com + /test/