]> code.citadel.org Git - citadel.git/blobdiff - ctdlphp/ctdlsession.php
* Cleanup
[citadel.git] / ctdlphp / ctdlsession.php
index a890e842149692bebc7d170fa755cdd9bdb9ee88..f2ac6f5237f052c468bd58766c7beb82ad993857 100644 (file)
@@ -5,11 +5,21 @@
 // This gets called from within the header functions.  It establishes or
 // connects to a PHP session, and then connects to Citadel if necessary.
 //
+// Web designers: please make changes in ctdlheader.php, not here.
+//
+// Copyright (c) 2003 by Art Cancro <ajc@uncensored.citadel.org>
+// This program is released under the terms of the GNU General Public License.
+
 
 function establish_citadel_session() {
 
        global $session, $clientsocket;
 
+       if (strcmp('4.3.0', phpversion()) > 0) {
+               die("This program requires PHP 4.3.0 or newer.");
+       }
+
+
        session_start();
 
        if ($_SESSION["ctdlsession"]) {
@@ -42,7 +52,7 @@ function establish_citadel_session() {
                // Ok, now try again.
                $clientsocket = fsockopen($sockname, 0, $errno, $errstr, 5);
 
-               // Try to log the user back in.
+               // Try to log the user back in and go back to the correct room.
                if ($clientsocket) {
 
                        ctdl_iden();    // Identify client
@@ -53,6 +63,13 @@ function establish_citadel_session() {
                                        $_SESSION["password"]
                                );
                        }
+
+                       if ($_SESSION["room"]) {
+                               ctdl_goto($_SESSION["room"]);
+                       }
+                       else {
+                               ctdl_goto("_BASEROOM_");
+                       }
                }
        }
 
@@ -65,6 +82,22 @@ function establish_citadel_session() {
                echo "ERROR: no Citadel socket!<BR>\n";
                flush();
        }
+
+       // If the user is trying to call up any page other than
+       // login.php logout.php do_login.php,
+       // and the session is not logged in, redirect to login.php
+       //
+       if ($_SESSION["logged_in"] != 1) {
+               $filename = basename(getenv('SCRIPT_NAME'));
+               if (    (strcmp($filename, "login.php"))
+                  &&   (strcmp($filename, "logout.php"))
+                  &&   (strcmp($filename, "do_login.php"))
+               ) {
+                       header("Location: login.php");
+                       exit(0);
+               }
+       }
+
        
 }