6 // This gets called from within the header functions. It establishes or
7 // connects to a PHP session, and then connects to Citadel if necessary.
10 function establish_citadel_session() {
12 global $session, $clientsocket;
16 if ($_SESSION["ctdlsession"]) {
17 $session = $_SESSION["ctdlsession"];
20 $session = "CtdlSession." . time() . rand(1000,9999) ;
21 $_SESSION["ctdlsession"] = $session;
24 // See if there's a Citadel connection proxy open for this session.
25 // The name of the socket is identical to the name of the
26 // session, and it's found in the /tmp directory.
28 $sockname = "/tmp/" . $session . ".socket" ;
30 $clientsocket = fsockopen($sockname, 0, $errno, $errstr, 5);
32 // It ain't there, dude. Open up the proxy. (C version)
33 //$cmd = "./sessionproxy " . $sockname ;
36 // It ain't there, dude. Open up the proxy. (PHP version)
37 $cmd = "./sessionproxy.php " . $sockname .
38 " </dev/null >/dev/null 2>&1 " .
39 " 3>&1 4>&1 5>&1 6>&1 7>&1 8>&1 & " ;
44 $clientsocket = fsockopen($sockname, 0, $errno, $errstr, 5);
46 // Try to log the user back in.
50 if ($_SESSION["username"]) {
52 $_SESSION["username"],
60 if (!$_SESSION["serv_humannode"]) {
65 echo "ERROR: no Citadel socket!<BR>\n";
73 // Clear out both our Citadel session and our PHP session. We're done.
75 function ctdl_end_session() {
76 global $clientsocket, $session;
78 // Tell the Citadel server to terminate our connection.
79 // (The extra newlines force it to see that the Citadel session
80 // ended, and the proxy will quit.)
82 fwrite($clientsocket, "QUIT\n\n\n\n\n\n\n\n\n\n\n");
83 $response = fgets($clientsocket, 4096); // IGnore response
84 fclose($clientsocket);
87 // Now clear our PHP session.
89 session_write_close();