###########################################
#-----------Users login system------------#
###########################################
/*=========================================\
Author      :  Mohammed Ahmed(M@@king)    \\
Version     :  1.0                        \\
Date Created:  Aug 20  2005               \\
----------------------------              \\
Last Update:   August 22 2005             \\
----------------------------              \\
Country    :   Palestine                  \\
City       :   Gaza                       \\
E-mail     :   m@maaking.com              \\
MSN        :   m@maaking.com              \\
AOL-IM     :   maa2pal                    \\
WWW        :   http://www.maaking.com     \\
Mobile/SMS :   00972-599-622235           \\
                                          \\
===========================================\
------------------------------------------*/
//skip the config file if somebody call it from the browser.
session_start();
if (eregi("config.php", $_SERVER['SCRIPT_NAME'])) {
    Header("Location: index.php"); 
    die();
}
//your database hostname.
$dbhost = "192.168.1.10";
//your database username.
$dbuname = "slowtwitch";
//your db password
$dbpass = "k9volqlAcpq";
$dbname = "slowtwitch";
//don't change unless you change this value in the db.
$prefix = "gforum_";
//change this
$site_name  = "Slowtwitch.com";
$site_email = "aaron@gossamer-threads.com";
$site_url = "http://forum.slowtwitch.com/survey/";
//added new code to fix compatibility issues.
//09-Nov-2005
$phpver = phpversion();
if ($phpver < '4.1.0') {
	$_GET = $HTTP_GET_VARS;
	$_POST = $HTTP_POST_VARS;
	$_SERVER = $HTTP_SERVER_VARS;
}
if ($phpver >= '4.0.4pl1' && strstr($_SERVER["HTTP_USER_AGENT"],'compatible')) {
	if (extension_loaded('zlib')) {
		ob_end_clean();
		ob_start('ob_gzhandler');
	}
} else if ($phpver > '4.0') {
	if (strstr($HTTP_SERVER_VARS['HTTP_ACCEPT_ENCODING'], 'gzip')) {
		if (extension_loaded('zlib')) {
			$do_gzip_compress = TRUE;
			ob_start(array('ob_gzhandler',5));
			ob_implicit_flush(0);
			header('Content-Encoding: gzip');
		}
	}
}
$phpver = explode(".", $phpver);
$phpver = "$phpver[0]$phpver[1]";
if ($phpver >= 41) {
	$PHP_SELF = $_SERVER['PHP_SELF'];
}
if (!ini_get("register_globals")) {
	import_request_variables('GPC');
}
include("mysql.class.php");
$db = new sql_db($dbhost, $dbuname, $dbpass, $dbname, false);
if(!$db->db_connect_id) {
      echo "
Error:
            Connection to database failed
            
";
      exit();
}
function get_sid() {
    if (isset($_SESSION['cookie']) and $_SESSION['cookie']) {
        return '';
    }
    else {
        return '&'.SID;
    }
}
//global function for checking whether user is logged in or not.
//you will notice we will use it everwhere in the script.
function is_logged_in($user) {
    global $db,$prefix;
    // return true if we're already logged in
    if (isset($_SESSION['user'])) {
        return 1;
    }
    // try and get the session id
    if (isset($_REQUEST['gforum_1022870964_session'])) {
        $session_id = $_REQUEST['gforum_1022870964_session'];
    }
    else if ($_REQUEST['from'] == 'gforum') {
        foreach ($_COOKIE as $key => $value) {
            if (preg_match('/gforum.*session/', $key)) {
                $session_id = $value;
                break;
            }
        }
        if (! isset($session_id)) {
            return 0;
        }
    }
    // return false if we have no login info
    else {
        return 0;
    }
    $result = mysql_query("SELECT session_user_id FROM ".$prefix."Session WHERE session_id='$session_id'") or die (mysql_error());
    $row = mysql_fetch_array($result);
    $user_id = $row['session_user_id'];
    $result = mysql_query("SELECT user_username,user_password,user_last_logon FROM ".$prefix."User WHERE user_id='$user_id'");
    $row = mysql_fetch_array($result);
    $_SESSION['user'] = base64_encode($row['user_username']);
    $_SESSION['password'] = base64_encode($row['user_password']);
    $_SESSION['user_id'] = base64_encode($user_id);
    $_SESSION['session_id'] = $session_id;
    $_SESSION['cookie'] = !(isset($_REQUEST['session']));
    // we're now logged in, so return 1
    return 1;
    // TODO: SLOWTWITCH CHANGE END
}
?>