5 // This gets called from within the header functions. It establishes or
6 // connects to a PHP session, and then connects to Citadel if necessary.
9 function establish_citadel_session() {
11 global $session, $clientsocket;
15 if ($_SESSION["ctdlsession"]) {
16 $session = $_SESSION["ctdlsession"];
19 $session = "CtdlSession." . time() . rand(1000,9999) ;
20 $_SESSION["ctdlsession"] = $session;
23 // See if there's a Citadel connection proxy open for this session.
24 // The name of the socket is identical to the name of the
25 // session, and it's found in the /tmp directory.
27 $sockname = "/tmp/" . $session . ".socket" ;
29 $clientsocket = fsockopen($sockname, 0, $errno, $errstr, 5);
31 // It ain't there, dude. Open up the proxy. (C version)
32 //$cmd = "./sessionproxy " . $sockname ;
35 // It ain't there, dude. Open up the proxy. (PHP version)
36 $cmd = "./sessionproxy.php " . $sockname .
37 " </dev/null >/dev/null 2>&1 " .
38 " 3>&1 4>&1 5>&1 6>&1 7>&1 8>&1 & " ;
43 $clientsocket = fsockopen($sockname, 0, $errno, $errstr, 5);
45 // Try to log the user back in.
49 if ($_SESSION["username"]) {
51 $_SESSION["username"],
59 if (!$_SESSION["serv_humannode"]) {
64 echo "ERROR: no Citadel socket!<BR>\n";
72 // Clear out both our Citadel session and our PHP session. We're done.
74 function ctdl_end_session() {
75 global $clientsocket, $session;
77 // Tell the Citadel server to terminate our connection.
78 // (The extra newlines force it to see that the Citadel session
79 // ended, and the proxy will quit.)
81 fwrite($clientsocket, "QUIT\n\n\n\n\n\n\n\n\n\n\n");
82 $response = fgets($clientsocket, 4096); // IGnore response
83 fclose($clientsocket);
86 // Now clear our PHP session.
88 session_write_close();