Make sure base_uri is correct (submitted by James Lewis)
[squirrelmail.git] / functions / auth.php
index ba8a6de1ec05b6ac0fced55142293000dbb806fe..6ce4e4a69f7c582e3d10ba496cda825a3ee7b645 100644 (file)
  * $Id$
  */
 
-/*****************************************************************/
-/*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!!           ***/
-/*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION.             ***/
-/***    + Base level indent should begin at left margin, as    ***/
-/***      the require_once below.                              ***/
-/***    + All identation should consist of four space blocks   ***/
-/***    + Tab characters are evil.                             ***/
-/***    + all comments should use "slash-star ... star-slash"  ***/
-/***      style -- no pound characters, no slash-slash style   ***/
-/***    + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD      ***/
-/***      ALWAYS USE { AND } CHARACTERS!!!                     ***/
-/***    + Please use ' instead of ", when possible. Note "     ***/
-/***      should always be used in _( ) function calls.        ***/
-/*** Thank you for your help making the SM code more readable. ***/
-/*****************************************************************/
-
 require_once( '../functions/page_header.php' );
 
-    function is_logged_in () {
-        global $squirrelmail_language;
+/* If a user opens a new session then comes back to this one,
+ * $base_uri isn't set because it the session is invalid.
+ */
 
-        if ( session_is_registered('user_is_logged_in') )
-            return;
+if (! isset($base_uri)) {
+    ereg ('(^.*/)[^/]+/[^/]+$', $PHP_SELF, $regs);
+    $base_uri = $regs[1];
+}
 
-        set_up_language($squirrelmail_language, true);
+function is_logged_in () {
+    global $squirrelmail_language, $frame_top, $base_uri;
 
-        displayHtmlHeader( 'SquirrelMail', '', FALSE );
+    if ( session_is_registered('user_is_logged_in') ) {
+        return;
+    }
 
-        echo "<body bgcolor=\"ffffff\">\n" .
-            '<br><br><center><b>'.
-            _("You must be logged in to access this page.").'</b><br><br>'.
-            "<a href=\"../src/login.php\" target=\"_top\">"._("Go to the login page")."</a>\n".
-            "</center></body></html>\n";
-        exit;
+    if (!isset($frame_top) || $frame_top == '' ) {
+        $frame_top = '_top';
     }
 
+    set_up_language($squirrelmail_language, true);
+
+    displayHtmlHeader( 'SquirrelMail', '', FALSE );
+
+    echo "<body bgcolor=\"ffffff\">\n" .
+         '<br><br><center><b>' .
+         _("You must be logged in to access this page.").'</b><br><br>' .
+         "<a href=\"$base_uri" . "src/login.php\" target=\"$frame_top\">"._("Go to the login page")."</a>\n" .
+         "</center></body></html>\n";
+    exit;
+}
+
 ?>