Location: PHPKode > projects > pkZoos Website > includes/user.php
<?php
	if(!defined('PK_MAGIC'))
		die('hack or what?');

    $user = array();

    function user_login()
    {
		global $db;
		global $config;
		global $user;
		global $tpl;

		$user['logged_in'] = 0;

        if(isset($_COOKIE[$config['cookie_name']]))
        {
            $cookie = unserialize($_COOKIE[$config['cookie_name']]);

            if(isset($cookie['id']) && isset($cookie['bn']) && isset($cookie['pw']))
            {
                $q = "
                    SELECT
                        user_id,
                        user_name,
                        lang_id,
                        style_id,
                        topics_per_page,
                        posts_per_page,
                        user_sigtext,
                        last_post_time,
                        last_topic_time,
                        user_is_admin,
                        user_is_member
                    FROM " . USERS_TABLE . "
                    WHERE
                        user_id          = '" . $db->escape($cookie['id']) . "' AND
                        user_name        = '" . $db->escape($cookie['bn']) . "' AND
                        user_password    = '" . $db->escape($cookie['pw']) . "' AND
                        user_is_disabled = 0
                ";

                $user_res = $db->query($q);

                if($user_row = $db->fetch_row($user_res))
                {
                    $user['id'] = $user_row['user_id'];
                    $user['name'] = $user_row['user_name'];
                    $user['sigtext'] = $user_row['user_sigtext'];
                    $user['last_post_time'] = $user_row['last_post_time'];
                    $user['last_topic_time'] = $user_row['last_topic_time'];
                    $user['is_mod'] = 0;
                    $user['is_admin'] = $user_row['user_is_admin'];
                    $user['is_member'] = $user_row['user_is_member'];

                    $config['lang_id'] = $user_row['lang_id'];
                    $config['style_id'] = $user_row['style_id'];
                    $config['topics_per_page'] = $user_row['topics_per_page'];
                    $config['posts_per_page'] = $user_row['posts_per_page'];

                    $user['logged_in'] = 1;
                }
            }
        }

        if(!$user['logged_in'])
        {
            setcookie($config['cookie_name'], '', CURRENT_TIME - 31536000, $config['cookie_path'], $config['cookie_domain'], $config['cookie_secure']);

            $user['id'] = 0;
            $user['name'] = '';
            $user['sigtext'] = '';
            $user['is_mod'] = 0;
            $user['is_admin'] = 0;
        }

        $tpl->add_vars
        (
        	array
        	(
        		'U_LOGGED_IN' => $user['logged_in'],
        		'U_IS_ADMIN' => $user['is_admin'],
        		'U_IS_MOD' => $user['is_mod'],
        		'U_NAME' => html_escape($user['name']),
        		'U_URL' => $user['logged_in'] ? html_escape(make_url('user', array('user_id' => $user['id']))) : ''
        	)
        );
    }
?>
Return current item: pkZoos Website