Skip to content

Instantly share code, notes, and snippets.

@ethaizone
Created January 26, 2015 14:35
Show Gist options
  • Save ethaizone/aebf5e4d19cddb729b0a to your computer and use it in GitHub Desktop.
Save ethaizone/aebf5e4d19cddb729b0a to your computer and use it in GitHub Desktop.
Lazy method but work - Helper for get baseUrl and basePath for website/webapp development
<?php
if ( ! function_exists('basePath'))
{
/**
* Get the path to the base of the install.
*
* @param string $path
* @return string
*/
function basePath($path = '')
{
$baseData = $_SERVER['SCRIPT_FILENAME'];
$posIndex = strpos( $baseData, '/'.basename($baseData));
$base = substr( $baseData, 0, $posIndex);
$base = $path ? $base.'/'.$path : $base;
return $base;
}
}
if (! function_exists('baseUrl'))
{
/**
* Get base path of url
*
* @param string $path
* @return string
*/
function baseUrl($path = '')
{
$baseData = $_SERVER['PHP_SELF'];
$posIndex = strpos( $baseData, '/'.basename($baseData));
$base = substr( $baseData, 0, $posIndex);
$base = $path ? $base.'/'.$path : $base;
return $base;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment