Initial commit - Last War messaging system
This commit is contained in:
40
includes/url_helper.php
Executable file
40
includes/url_helper.php
Executable file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
function getBaseUrl(): string
|
||||
{
|
||||
$protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
|
||||
$host = $_SERVER['HTTP_HOST'] ?? 'localhost';
|
||||
|
||||
return "{$protocol}://{$host}";
|
||||
}
|
||||
|
||||
function getAppUrl(string $path = ''): string
|
||||
{
|
||||
return getBaseUrl() . '/' . ltrim($path, '/');
|
||||
}
|
||||
|
||||
function site_url(string $path = ''): string
|
||||
{
|
||||
return getAppUrl($path);
|
||||
}
|
||||
|
||||
function asset(string $path): string
|
||||
{
|
||||
return getAppUrl('assets/' . ltrim($path, '/'));
|
||||
}
|
||||
|
||||
function url(string $path): string
|
||||
{
|
||||
return getAppUrl($path);
|
||||
}
|
||||
|
||||
function redirect(string $path): void
|
||||
{
|
||||
header('Location: ' . site_url($path));
|
||||
exit;
|
||||
}
|
||||
|
||||
function current_url(): string
|
||||
{
|
||||
return getBaseUrl() . ($_SERVER['REQUEST_URI'] ?? '/');
|
||||
}
|
||||
Reference in New Issue
Block a user