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;
13 if (strcmp('4.3.0', phpversion()) > 0) {
14 die("This program requires PHP 4.3.0 or newer.");
20 if ($_SESSION["ctdlsession"]) {
21 $session = $_SESSION["ctdlsession"];
24 $session = "CtdlSession." . time() . rand(1000,9999) ;
25 $_SESSION["ctdlsession"] = $session;
28 // See if there's a Citadel connection proxy open for this session.
29 // The name of the socket is identical to the name of the
30 // session, and it's found in the /tmp directory.
32 $sockname = "/tmp/" . $session . ".socket" ;
34 $clientsocket = fsockopen($sockname, 0, $errno, $errstr, 5);
36 // It ain't there, dude. Open up the proxy. (C version)
37 //$cmd = "./sessionproxy " . $sockname ;
40 // It ain't there, dude. Open up the proxy. (PHP version)
41 $cmd = "./sessionproxy.php " . $sockname .
42 " </dev/null >/dev/null 2>&1 " .
43 " 3>&1 4>&1 5>&1 6>&1 7>&1 8>&1 & " ;
48 $clientsocket = fsockopen($sockname, 0, $errno, $errstr, 5);
50 // Try to log the user back in and go back to the correct room.
53 ctdl_iden(); // Identify client
55 if ($_SESSION["username"]) {
57 $_SESSION["username"],
62 if ($_SESSION["room"]) {
63 ctdl_goto($_SESSION["room"]);
66 ctdl_goto("_BASEROOM_");
72 if (!$_SESSION["serv_humannode"]) {
77 echo "ERROR: no Citadel socket!<BR>\n";
81 // If the user is trying to call up any page other than
82 // login.php logout.php do_login.php,
83 // and the session is not logged in, redirect to login.php
85 if ($_SESSION["logged_in"] != 1) {
86 $filename = basename(getenv('SCRIPT_NAME'));
87 if ( (strcmp($filename, "login.php"))
88 && (strcmp($filename, "logout.php"))
89 && (strcmp($filename, "do_login.php"))
91 header("Location: login.php");
101 // Clear out both our Citadel session and our PHP session. We're done.
103 function ctdl_end_session() {
104 global $clientsocket, $session;
106 // Tell the Citadel server to terminate our connection.
107 // (The extra newlines force it to see that the Citadel session
108 // ended, and the proxy will quit.)
110 fwrite($clientsocket, "QUIT\n\n\n\n\n\n\n\n\n\n\n");
111 $response = fgets($clientsocket, 4096); // IGnore response
112 fclose($clientsocket);
113 unset($clientsocket);
115 // Now clear our PHP session.
117 session_write_close();