Introduced detectServerUrl() which makes configuration of static 'url'
authorRoland Häder <roland@mxchange.org>
Thu, 31 Mar 2016 07:20:04 +0000 (09:20 +0200)
committerRoland Häder <roland@mxchange.org>
Thu, 31 Mar 2016 07:20:04 +0000 (09:20 +0200)
automatic.

index.php

index 9d8a4e867be41a75c70eb8a12dc63a3cc9fd847c..883405c9a6da38d97e69066d9ed517e2787fe01a 100644 (file)
--- 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'];
                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');