]> code.citadel.org Git - citadel.git/blobdiff - ctdlphp/ctdlsession.php
* Got login/logout working. Still need to redirect unloggedin sessions to
[citadel.git] / ctdlphp / ctdlsession.php
index fe0e374f3e6a526e180db73bb304a1b89afa7712..5683467abae3f93b76b9e42be3ea535b28fb588b 100644 (file)
@@ -11,10 +11,15 @@ function establish_citadel_session() {
 
        global $session, $clientsocket;
 
-       // echo "Calling session_start()<BR>\n";
-       // flush();
        session_start();
-       $session = "CtdlSession." . session_id();
+
+       if ($_SESSION["ctdlsession"]) {
+               $session = $_SESSION["ctdlsession"];
+       }
+       else {
+               $session = "CtdlSession." . time() . rand(1000,9999) ;
+               $_SESSION["ctdlsession"] = $session;
+       }
 
        // See if there's a Citadel connection proxy open for this session.
        // The name of the socket is identical to the name of the
@@ -22,8 +27,6 @@ function establish_citadel_session() {
 
        $sockname = "/tmp/" . $session . ".socket" ;
 
-       // echo "Connecting to ", $sockname, "...<BR>\n";
-       // flush();
        $clientsocket = fsockopen($sockname, 0, $errno, $errstr, 5);
        if (!$clientsocket) {
                // It ain't there, dude.  Open up the proxy. (C version)
@@ -39,24 +42,24 @@ function establish_citadel_session() {
 
                // Ok, now try again.
                $clientsocket = fsockopen($sockname, 0, $errno, $errstr, 5);
+
+               // Try to log the user back in.
+               if ($clientsocket) {
+
+
+                       if ($_SESSION["username"]) {
+                               login_existing_user(
+                                       $_SESSION["username"],
+                                       $_SESSION["password"]
+                               );
+                       }
+               }
        }
 
        if ($clientsocket) {
-               /*
-               echo "Connected.  Performing echo tests.<BR>\n";
-               flush();
-               $cmd = "ECHO test echo string upon connection\n";
-               fwrite($clientsocket, $cmd);
-               $response = fgets($clientsocket, 4096);
-               echo "Response is: ", $response, "<BR>\n";
-               flush();
-
-               $cmd = "ECHO second test for echo\n";
-               fwrite($clientsocket, $cmd);
-               $response = fgets($clientsocket, 4096);
-               echo "Response is: ", $response, "<BR>\n";
-               flush();
-               */
+               if (!$_SESSION["serv_humannode"]) {
+                       ctdl_get_serv_info();
+               }
        }
        else {
                echo "ERROR: no Citadel socket!<BR>\n";
@@ -73,13 +76,16 @@ function ctdl_end_session() {
        global $clientsocket, $session;
 
        // Tell the Citadel server to terminate our connection.
-       fwrite($clientsocket, "QUIT\n");
+       // (The extra newlines force it to see that the Citadel session
+       // ended, and the proxy will quit.)
+       //
+       fwrite($clientsocket, "QUIT\n\n\n\n\n\n\n\n\n\n\n");
        $response = fgets($clientsocket, 4096);         // IGnore response
        fclose($clientsocket);
        unset($clientsocket);
 
        // Now clear our PHP session.
-       unset($session); 
+       $_SESSION = array();
        session_write_close();
 }