📜  php 从脚本位置获取父 url - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:08.882000             🧑  作者: Mango

代码示例1
/* Just ran this as is and it worked
*  OUTPUT: http://rootURL.com/dir1/parentDIR/{script.php}
*/
function get_directory(){
    $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
    $protocol = substr(strtolower($_SERVER["SERVER_PROTOCOL"]), 0, strpos(strtolower($_SERVER["SERVER_PROTOCOL"]), "/")) . $s;
    $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
return $protocol . "://" . $_SERVER['SERVER_NAME'] . dirname($_SERVER['PHP_SELF']);
}
define("ROOT_PATH", get_directory()."/" );
echo ROOT_PATH;