note 100881 added to reserved.variables.server
| From: | (infoatsarchittudotorg) | Date: | Fri, 12 Nov 2010 14:07:22 +0000 |
| Subject: | note 100881 added to reserved.variables.server | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-173978@lists.php.net to get a copy of this message | ||
A way to get the absolute path of your page, independent from the site position (so works both on
local machine and on server without setting anything) and from the server OS (works both on Unix
systems and Windows systems).
The only parameter it requires is the folder in which you place this script
So, for istance, I'll place this into my SCRIPT folder, and I'll write SCRIPT word length
in $conflen
<?php
$conflen=strlen('SCRIPT');
$B=substr(__FILE__,0,strrpos(__FILE__,'/'));
$A=substr($_SERVER['DOCUMENT_ROOT'], strrpos($_SERVER['DOCUMENT_ROOT'],
$_SERVER['PHP_SELF']));
$C=substr($B,strlen($A));
$posconf=strlen($C)-$conflen-1;
$D=substr($C,1,$posconf);
$host='http://'.$_SERVER['SERVER_NAME'].'/'.$D;
?>
$host will finally contain the absolute path.
----
Server IP: 69.147.83.197
Probable Submitter: 93.37.20.46
----
Manual Page -- http://www.php.net/manual/en/reserved.variables.server.php
Edit -- https://master.php.net/note/edit/100881
Del: integrated -- https://master.php.net/note/delete/100881/integrated
Del: useless -- https://master.php.net/note/delete/100881/useless
Del: bad code -- https://master.php.net/note/delete/100881/bad+code
Del: spam -- https://master.php.net/note/delete/100881/spam
Del: non-english -- https://master.php.net/note/delete/100881/non-english
Del: in docs -- https://master.php.net/note/delete/100881/in+docs
Del: other reasons-- https://master.php.net/note/delete/100881
Reject -- https://master.php.net/note/reject/100881
Search -- https://master.php.net/manage/user-notes.php