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.
8 // Web designers: please make changes in ctdlheader.php, not here.
10 // Copyright (c) 2003 by Art Cancro <ajc@uncensored.citadel.org>
11 // This program is released under the terms of the GNU General Public License.
14 function establish_citadel_session() {
16 global $session, $clientsocket;
18 if (strcmp('4.3.0', phpversion()) > 0) {
19 die("This program requires PHP 4.3.0 or newer.");
25 if ($_SESSION["ctdlsession"]) {
26 $session = $_SESSION["ctdlsession"];
29 $session = "CtdlSession." . time() . rand(1000,9999) ;
30 $_SESSION["ctdlsession"] = $session;
33 // See if there's a Citadel connection proxy open for this session.
34 // The name of the socket is identical to the name of the
35 // session, and it's found in the /tmp directory.
37 $sockname = "/tmp/" . $session . ".socket" ;
39 $clientsocket = fsockopen($sockname, 0, $errno, $errstr, 5);
41 // It ain't there, dude. Open up the proxy. (C version)
42 //$cmd = "./sessionproxy " . $sockname ;
45 // It ain't there, dude. Open up the proxy. (PHP version)
46 $cmd = "./sessionproxy.php " . $sockname .
47 " </dev/null >/dev/null 2>&1 " .
48 " 3>&1 4>&1 5>&1 6>&1 7>&1 8>&1 & " ;
53 $clientsocket = fsockopen($sockname, 0, $errno, $errstr, 5);
55 // Try to log the user back in and go back to the correct room.
58 ctdl_iden(); // Identify client
60 if ($_SESSION["username"]) {
62 $_SESSION["username"],
67 if ($_SESSION["room"]) {
68 ctdl_goto($_SESSION["room"]);
71 ctdl_goto("_BASEROOM_");
77 if (!$_SESSION["serv_humannode"]) {
82 echo "ERROR: no Citadel socket!<BR>\n";
86 // If the user is trying to call up any page other than
87 // login.php logout.php do_login.php,
88 // and the session is not logged in, redirect to login.php
90 if ($_SESSION["logged_in"] != 1) {
91 $filename = basename(getenv('SCRIPT_NAME'));
92 if ( (strcmp($filename, "login.php"))
93 && (strcmp($filename, "logout.php"))
94 && (strcmp($filename, "do_login.php"))
96 header("Location: login.php");
106 // Clear out both our Citadel session and our PHP session. We're done.
108 function ctdl_end_session() {
109 global $clientsocket, $session;
111 // Tell the Citadel server to terminate our connection.
112 // (The extra newlines force it to see that the Citadel session
113 // ended, and the proxy will quit.)
115 fwrite($clientsocket, "QUIT\n\n\n\n\n\n\n\n\n\n\n");
116 $response = fgets($clientsocket, 4096); // IGnore response
117 fclose($clientsocket);
118 unset($clientsocket);
120 // Now clear our PHP session.
122 session_write_close();