Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * This snippet was originally written in Sébastien Lavoie's blog.
- * You can find the post at
- * http://blog.lavoie.sl/2013/02/php-document-root-path-and-url-detection.html
- */
- $baseDir = __DIR__;
- $docRoot = preg_replace( "!{$_SERVER['SCRIPT_NAME']}$!", '', $_SERVER['SCRIPT_FILENAME'] );
- $baseUrl = preg_replace( "!^{$docRoot}!", '', $baseDir );
- $protocol = empty( $_SERVER['HTTPS'] ) ? 'http' : 'https';
- $port = $_SERVER['SERVER_PORT'];
- $dispPort = ( $protocol == 'http' && $port == 80 || $protocol == 'https' && $port == 443 ) ? '' : ":$port";
- $domain = $_SERVER['SERVER_NAME'];
- $fullUrl = "$protocol://{$domain}{$dispPort}{$baseUrl}";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement