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;
14 // echo "Calling session_start()<BR>\n";
17 $session = "CtdlSession." . session_id();
19 // See if there's a Citadel connection proxy open for this session.
20 // The name of the socket is identical to the name of the
21 // session, and it's found in the /tmp directory.
23 $sockname = "/tmp/" . $session . ".socket" ;
25 // echo "Connecting to ", $sockname, "...<BR>\n";
27 $clientsocket = fsockopen($sockname, 0, $errno, $errstr, 5);
29 //echo "Socket not present. Firing up a new proxy.<BR>\n";
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 // echo "Connecting to ", $sockname, "...<BR>\n";
46 $clientsocket = fsockopen($sockname, 0, $errno, $errstr, 5);
51 echo "Connected. Performing echo tests.<BR>\n";
53 $cmd = "ECHO test echo string upon connection\n";
54 fwrite($clientsocket, $cmd);
55 $response = fgets($clientsocket, 4096);
56 echo "Response is: ", $response, "<BR>\n";
59 $cmd = "ECHO second test for echo\n";
60 fwrite($clientsocket, $cmd);
61 $response = fgets($clientsocket, 4096);
62 echo "Response is: ", $response, "<BR>\n";
67 echo "ERROR: no Citadel socket!<BR>\n";
75 // Clear out both our Citadel session and our PHP session. We're done.
77 function ctdl_end_session() {
78 global $clientsocket, $session;
80 // Tell the Citadel server to terminate our connection.
81 fwrite($clientsocket, "QUIT\n");
82 $response = fgets($clientsocket, 4096); // IGnore response
83 fclose($clientsocket);
86 // Now clear our PHP session.
88 session_write_close();