// This gets called from within the header functions. It establishes or
// connects to a PHP session, and then connects to Citadel if necessary.
//
+// Web designers: please make changes in ctdlheader.php, not here.
+//
+// Copyright (c) 2003 by Art Cancro <ajc@uncensored.citadel.org>
+// This program is released under the terms of the GNU General Public License.
+
function establish_citadel_session() {
" </dev/null >/dev/null 2>&1 " .
" 3>&1 4>&1 5>&1 6>&1 7>&1 8>&1 & " ;
exec($cmd);
- sleep(2);
-
- // Ok, now try again.
- $clientsocket = fsockopen($sockname, 0, $errno, $errstr, 5);
- // Try to log the user back in and go back to the correct room.
- if ($clientsocket) {
+ // Keep attempting connections 10 times per second up to 100 times
+ $attempts = 0;
+ while (!$clientsocket) {
+ usleep(100);
+ $clientsocket = fsockopen($sockname, 0, $errno, $errstr, 5);
+ $attempts += 1;
+ if ($attempts > 100) {
+ echo "ERROR: unable to start connection proxy. ";
+ echo "Please contact your system administrator.<BR>\n";
+ flush();
+ exit(1);
+ }
+ }
- ctdl_iden(); // Identify client
+ // At this point we have a good connection to Citadel.
- if ($_SESSION["username"]) {
- login_existing_user(
- $_SESSION["username"],
- $_SESSION["password"]
- );
- }
+ ctdl_iden(); // Identify client
- if ($_SESSION["room"]) {
- ctdl_goto($_SESSION["room"]);
- }
- else {
- ctdl_goto("_BASEROOM_");
- }
+ if ($_SESSION["username"]) {
+ login_existing_user(
+ $_SESSION["username"],
+ $_SESSION["password"]
+ );
}
- }
- if ($clientsocket) {
- if (!$_SESSION["serv_humannode"]) {
- ctdl_get_serv_info();
+ if ($_SESSION["room"]) {
+ ctdl_goto($_SESSION["room"]);
+ }
+ else {
+ ctdl_goto("_BASEROOM_");
}
}
- else {
- echo "ERROR: no Citadel socket!<BR>\n";
- flush();
+
+ if (!$_SESSION["serv_humannode"]) {
+ ctdl_get_serv_info();
}
// If the user is trying to call up any page other than