From a7a3f3ce5e4ef8a50bb0829f7a000f9af867b322 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Thu, 31 Mar 2016 09:20:04 +0200 Subject: [PATCH] Introduced detectServerUrl() which makes configuration of static 'url' automatic. --- index.php | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/index.php b/index.php index 9d8a4e8..883405c 100644 --- a/index.php +++ b/index.php @@ -59,8 +59,8 @@ // Display debugging information 'debug' => false, - // Complete URL to your directory (including tracing slash) - 'url' => 'http://strace.club/', + // Complete URL to your directory (including tracing slash, leave for auto-detection) + 'url' => detectServerUrl(), // Amount of seconds that each file should be stored for (0 for no limit) // Default 30 days @@ -99,7 +99,7 @@ $data = array(); // Name of this file - $data['scriptname'] = $settings['url'] . '/' . pathinfo(__FILE__, PATHINFO_BASENAME); + $data['scriptname'] = $settings['url'] . pathinfo(__FILE__, PATHINFO_BASENAME); // Adding current script name to ignore list $data['ignores'] = $settings['ignores']; @@ -246,6 +246,27 @@ return (is_file($file) && is_readable($file)); } + // Detects full URL of installation + function detectServerUrl () { + // Is "cache" there? + if (!isset($GLOBALS[__FUNCTION__])) { + // Default protocol is HTTP + $protocol = 'http'; + + // Is SSL given? + if (((isset($_SERVER['HTTPS'])) && (strtolower($_SERVER['HTTPS']) == 'on')) || ((isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) && (strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https'))) { + // Protocol is HTTPS + $protocol = 'https'; + } // END - if + + // Construct full URL + $GLOBALS[__FUNCTION__] = str_replace("\\", '', sprintf('%s://%s%s/', $protocol, $_SERVER['SERVER_NAME'], dirname($_SERVER['SCRIPT_NAME']))); + } // END - if + + // Return cached value + return $GLOBALS[__FUNCTION__]; + } + // Files are being POSEed. Uploading them one by one. if (isset($_FILES['file'])) { header('Content-type: text/plain'); -- 2.39.5