- /**
- * This determines the location to forward to relative to your server.
- * If this doesnt work correctly for you (although it should), you can
- * remove all this code except the last two lines, and change the header()
- * function to look something like this, customized to the location of
- * SquirrelMail on your server:
- *
- * http://www.myhost.com/squirrelmail/src/login.php
- */
- function get_location () {
-
- global $PHP_SELF, $SERVER_NAME, $HTTP_HOST, $SERVER_PORT,
- $HTTP_SERVER_VARS;
-
- /* Get the path. */
- $path = substr($PHP_SELF, 0, strrpos($PHP_SELF, '/'));
-
- /* Check if this is a HTTPS or regular HTTP request. */
- $proto = 'http://';
-
- /*
- * If you have 'SSLOptions +StdEnvVars' in your apache config
- * OR if you have HTTPS in your HTTP_SERVER_VARS
- * OR if you are on port 443
- */
- $getEnvVar = getenv('HTTPS');
- if ((isset($getEnvVar) && !strcasecmp($getEnvVar, 'on')) ||
- (isset($HTTP_SERVER_VARS['HTTPS'])) ||
- (isset($HTTP_SERVER_VARS['SERVER_PORT']) &&
- $HTTP_SERVER_VARS['SERVER_PORT'] == 443)) {
+/**
+ * Determines the location to forward to, relative to your server.
+ * This is used in HTTP Location: redirects.
+ * If this doesnt work correctly for you (although it should), you can
+ * remove all this code except the last two lines, and have it return
+ * the right URL for your site, something like:
+ *
+ * http://www.example.com/squirrelmail/
+ *
+ * @return string the base url for this SquirrelMail installation
+ */
+function get_location () {
+
+ global $imap_server_type;
+
+ /* Get the path, handle virtual directories */
+ if(strpos(php_self(), '?')) {
+ $path = substr(php_self(), 0, strpos(php_self(), '?'));
+ } else {
+ $path = php_self();
+ }
+ $path = substr($path, 0, strrpos($path, '/'));
+ if ( sqgetGlobalVar('sq_base_url', $full_url, SQ_SESSION) ) {
+ return $full_url . $path;
+ }
+
+ /* Check if this is a HTTPS or regular HTTP request. */
+ $proto = 'http://';
+
+ /*
+ * If you have 'SSLOptions +StdEnvVars' in your apache config
+ * OR if you have HTTPS=on in your HTTP_SERVER_VARS
+ * OR if you are on port 443
+ */
+ $getEnvVar = getenv('HTTPS');
+ if ((isset($getEnvVar) && !strcasecmp($getEnvVar, 'on')) ||
+ (sqgetGlobalVar('HTTPS', $https_on, SQ_SERVER) && !strcasecmp($https_on, 'on')) ||
+ (sqgetGlobalVar('SERVER_PORT', $server_port, SQ_SERVER) && $server_port == 443)) {