]> code.citadel.org Git - citadel.git/blobdiff - ctdlphp/ctdlsession.php
* When sending the QUIT command to the server, output a bunch more newlines
[citadel.git] / ctdlphp / ctdlsession.php
index 605529b52d1ec158e52763eeb5cc89cd6447bb55..6669eac75af8d4007841273844f834b4c1216050 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,13 +27,8 @@ function establish_citadel_session() {
 
        $sockname = "/tmp/" . $session . ".socket" ;
 
-       // echo "Connecting to ", $sockname, "...<BR>\n";
-       // flush();
        $clientsocket = fsockopen($sockname, 0, $errno, $errstr, 5);
        if (!$clientsocket) {
-               //echo "Socket not present.  Firing up a new proxy.<BR>\n";
-               //flush();
-
                // It ain't there, dude.  Open up the proxy. (C version)
                //$cmd = "./sessionproxy " . $sockname ;
                //exec($cmd);
@@ -41,8 +41,6 @@ function establish_citadel_session() {
                sleep(2);
 
                // Ok, now try again.
-               // echo "Connecting to ", $sockname, "...<BR>\n";
-               // flush();
                $clientsocket = fsockopen($sockname, 0, $errno, $errstr, 5);
        }
 
@@ -51,13 +49,13 @@ function establish_citadel_session() {
                echo "Connected.  Performing echo tests.<BR>\n";
                flush();
                $cmd = "ECHO test echo string upon connection\n";
-               fwrite($clientsocket, $cmd, strlen($cmd));
+               fwrite($clientsocket, $cmd);
                $response = fgets($clientsocket, 4096);
                echo "Response is: ", $response, "<BR>\n";
                flush();
 
                $cmd = "ECHO second test for echo\n";
-               fwrite($clientsocket, $cmd, strlen($cmd));
+               fwrite($clientsocket, $cmd);
                $response = fgets($clientsocket, 4096);
                echo "Response is: ", $response, "<BR>\n";
                flush();
@@ -71,15 +69,24 @@ function establish_citadel_session() {
 }
 
 
+//
+// Clear out both our Citadel session and our PHP session.  We're done.
+//
 function ctdl_end_session() {
        global $clientsocket, $session;
 
-       session_destroy();
+       // Tell the Citadel server to terminate our connection.
+       // (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);
-       unset($session); 
 
-       echo "Session destroyed.<BR>\n";
-       
+       // Now clear our PHP session.
+       $_SESSION = array();
+       session_write_close();
 }
 
 ?>