blob: 8bfa02981ed256092c4c5147784f561be343748c (
plain) (
tree)
|
|
<?php
/*
* SCROTT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*
* For more information, please refer to UNLICENSE
*/
/*
* This file defines various functions which exist in the global namespace.
* These are utility functions and constants for the Scrott application.
*/
define("__VERSION__", "v0.0");
/*
* Get the application root path. This is an absolute path on the server.
*/
function ar() : string
{
return substr($_SERVER['SCRIPT_NAME'], 0, -10); // 10 = strlen of "/index.php"
}
/*
* Get the current page's path. This is an absolute path on the server.
*/
function ap() : string
{
return ar() . $_SERVER['PATH_INFO'];
}
/*
* Redirect to the given URL and die.
*/
function redirect(string $url) : void
{
header("Location: " . $url);
exit;
}
/*
* Redirect to the given in-app URL and die. The given URL should be a path
* relative to the app root.
*/
function location(string $path) : void
{
redirect(ar() . $path);
}
/*
* Assert that the current connection to the server is over HTTPS. Redirect
* if not.
*/
function require_https() : void
{
if (!isset($_SERVER['HTTPS']))
redirect("https://" . $_SERVER['SERVER_NAME'] . ap());
}
?>
|