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 // It ain't there, dude. Open up the proxy. (C version)
30 //$cmd = "./sessionproxy " . $sockname ;
33 // It ain't there, dude. Open up the proxy. (PHP version)
34 $cmd = "./sessionproxy.php " . $sockname .
35 " </dev/null >/dev/null 2>&1 " .
36 " 3>&1 4>&1 5>&1 6>&1 7>&1 8>&1 & " ;
41 $clientsocket = fsockopen($sockname, 0, $errno, $errstr, 5);
46 echo "Connected. Performing echo tests.<BR>\n";
48 $cmd = "ECHO test echo string upon connection\n";
49 fwrite($clientsocket, $cmd);
50 $response = fgets($clientsocket, 4096);
51 echo "Response is: ", $response, "<BR>\n";
54 $cmd = "ECHO second test for echo\n";
55 fwrite($clientsocket, $cmd);
56 $response = fgets($clientsocket, 4096);
57 echo "Response is: ", $response, "<BR>\n";
62 echo "ERROR: no Citadel socket!<BR>\n";
70 // Clear out both our Citadel session and our PHP session. We're done.
72 function ctdl_end_session() {
73 global $clientsocket, $session;
75 // Tell the Citadel server to terminate our connection.
76 fwrite($clientsocket, "QUIT\n");
77 $response = fgets($clientsocket, 4096); // IGnore response
78 fclose($clientsocket);
81 // Now clear our PHP session.
83 session_write_close();