Fix pb when host on domain name starting with 'admin'

* Do str_replace only on the $dirname variable
This commit is contained in:
Olivier PEREZ 2015-03-04 23:46:42 +01:00
parent 818151fe83
commit b3bc68bbe6
2 changed files with 6 additions and 5 deletions

View File

@ -23,13 +23,14 @@ class Utils {
* @return string Server name * @return string Server name
*/ */
public static function get_server_name() { public static function get_server_name() {
$scheme = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') ? 'https' : 'http'; $scheme = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') ? 'https' : 'http';
$port = in_array($_SERVER['SERVER_PORT'], [80, 443]) ? '' : ':' . $_SERVER['SERVER_PORT']; $port = in_array($_SERVER['SERVER_PORT'], [80, 443]) ? '' : ':' . $_SERVER['SERVER_PORT'];
$dirname = dirname($_SERVER['SCRIPT_NAME']); $dirname = dirname($_SERVER['SCRIPT_NAME']);
$dirname = $dirname === '\\' ? '/' : $dirname . '/'; $dirname = $dirname === '\\' ? '/' : $dirname . '/';
$dirname = str_replace('/admin', '', $dirname);
$server_name = $_SERVER['SERVER_NAME'] . $port . $dirname; $server_name = $_SERVER['SERVER_NAME'] . $port . $dirname;
return $scheme . '://' . str_replace('/admin', '', str_replace('//', '/', str_replace('///', '/', $server_name))); return $scheme . '://' . preg_replace('//+', '/', $server_name);
} }
public static function is_error($cerr) { public static function is_error($cerr) {

View File

@ -38,7 +38,7 @@ function bandeau_titre($titre)
</form>'; </form>';
} }
echo ' echo '
<h1><a href="'.str_replace('/admin','', Utils::get_server_name()).'" title="'._("Home").' - '.NOMAPPLICATION.'">'.$img.'</a></h1> <h1><a href="' . Utils::get_server_name() . '" title="' . _('Home') . ' - ' . NOMAPPLICATION . '">' . $img . '</a></h1>
<h2 class="lead"><i>'. $titre .'</i></h2> <h2 class="lead"><i>'. $titre .'</i></h2>
<hr class="trait" role="presentation" /> <hr class="trait" role="presentation" />
</header> </header>
@ -72,7 +72,7 @@ function liste_lang()
return $str; return $str;
} }
function bandeau_pied($admin=false) function bandeau_pied()
{ {
echo ' echo '
</main> </main>