Skip to content

Instantly share code, notes, and snippets.

@asika32764
Created June 1, 2019 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asika32764/6841c14b12e64a469eb46993ef7ea7db to your computer and use it in GitHub Desktop.
Save asika32764/6841c14b12e64a469eb46993ef7ea7db to your computer and use it in GitHub Desktop.
Very simple way to get PHP URL path with subfolder.
<?php
define('APP_ROOT', __DIR__); // Change this to root dir.
define('HTTP_TYPE', (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] === 443 ? 'https' : 'http');
define('HTTP_ROOT', $_SERVER['HTTP_HOST']);
define('BASE_URL', HTTP_TYPE . '://' . HTTP_ROOT . substr(APP_ROOT, strlen($_SERVER[ 'DOCUMENT_ROOT' ])) . '/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment