Index: trunk/lib/App.inc.php
===================================================================
--- trunk/lib/App.inc.php	(revision 676)
+++ trunk/lib/App.inc.php	(revision 679)
@@ -78,5 +78,6 @@
         'site_name' => null,
         'site_email' => '', // Set to no-reply@HTTP_HOST if not set here.
-        'site_hostname' => '', // The hostname of this application (if not set, use a cleaned HTTP_HOST environment variable).
+        'site_hostname' => '', // The hostname of this application (if not set, derived from HTTP_HOST).
+        'site_port' => '', // The hostname of this application (if not set, derived from HTTP_HOST).
         'site_url' => '', // URL to the root of the site (created during App->start()).
         'page_url' => '', // URL to the current page (created during App->start()).
@@ -146,5 +147,5 @@
         'db_pass' => null,
 
-        // And for CLI scripts, which should include a JSON file at this specified location in the include path.
+        // CLI scripts will need this JSON file in the include path.
         'db_auth_file' => 'db_auth.json',
 
@@ -479,8 +480,13 @@
          */
 
-        // To get a safe hostname, remove host port and invalid hostname characters.
+        // To get a safe hostname, remove port and invalid hostname characters.
         $safe_http_host = preg_replace('/[^a-z\d.:-]/', '', strtok(getenv('HTTP_HOST'), ':'));
+        // If strtok() matched a ':' in the previous line, the rest of the string contains the port number (or FALSE)
+        $safe_http_port = preg_replace('/[^0-9]/', '', strtok(''));
         if ('' != $safe_http_host && '' == $this->getParam('site_hostname')) {
             $this->setParam(array('site_hostname' => $safe_http_host));
+        }
+        if ('' != $safe_http_port && '' == $this->getParam('site_port')) {
+            $this->setParam(array('site_port' => $safe_http_port));
         }
 
@@ -489,5 +495,5 @@
         // Not available on CLI scripts obviously.
         if ('' != $safe_http_host && '' == $this->getParam('site_url')) {
-            $this->setParam(array('site_url' => sprintf('%s://%s', (getenv('HTTPS') ? 'https' : 'http'), $safe_http_host)));
+            $this->setParam(array('site_url' => sprintf('%s://%s%s', (getenv('HTTPS') ? 'https' : 'http'), $safe_http_host, (preg_match('/^(|80|443)$/', $safe_http_port) ? '' : ':' . $safe_http_port))));
         }
 
@@ -495,5 +501,5 @@
         // Also not available on CLI scripts obviously.
         if ('' != $safe_http_host) {
-            $this->setParam(array('page_url' => sprintf('%s://%s%s', (getenv('HTTPS') ? 'https' : 'http'), $safe_http_host, getenv('REQUEST_URI'))));
+            $this->setParam(array('page_url' => sprintf('%s%s', $this->getParam('site_url'), getenv('REQUEST_URI'))));
         }
 
@@ -1396,8 +1402,6 @@
 
         if (preg_match('!^/!', $url)) {
-            // If relative URL is given, prepend correct local hostname.
-            $scheme = getenv('HTTPS') ? 'https' : 'http';
-            $host = $this->getParam('site_hostname');
-            $url = sprintf('%s://%s%s', $scheme, $host, $url);
+            // If relative URL is given, prepend site_url, which contains: scheme://hostname[:port]
+            $url = sprintf('%s%s', $this->getParam('site_url'), $url);
         }
 
@@ -1705,5 +1709,5 @@
 
     /*
-    * Set timezone used internally by PHP.
+    * Set timezone used internally by PHP. See full list at https://www.php.net/manual/en/timezones.php
     *
     * @access   public
Index: trunk/lib/DB.inc.php
===================================================================
--- trunk/lib/DB.inc.php	(revision 676)
+++ trunk/lib/DB.inc.php	(revision 679)
@@ -339,5 +339,9 @@
         $debugqry = preg_replace("/\n[\t ]+/", "\n", $query);
         if ($this->getParam('db_always_debug') || $debug) {
-            echo "<!-- ----------------- Query $this->_query_count ---------------------\n$debugqry\n-->\n";
+            if ($debug > 1) {
+                dump($debugqry, true, SC_DUMP_PRINT_R, __FILE__, __LINE__);
+            } else {
+                echo "<!-- ----------------- Query $this->_query_count ---------------------\n$debugqry\n-->\n";
+            }
         }
 
Index: trunk/lib/Utilities.inc.php
===================================================================
--- trunk/lib/Utilities.inc.php	(revision 676)
+++ trunk/lib/Utilities.inc.php	(revision 679)
@@ -1452,6 +1452,7 @@
     $ch = curl_init($url);
     curl_setopt($ch, CURLOPT_TIMEOUT, 5);
+    curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
-    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
     curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36");
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Don't pass through data to the browser.
