Current time: 11-23-2024, 12:38 PM Hello There, Guest! (LoginRegister)


Thread Closed 
Simplify php code
Author Message
sci2tech Away
Senior Member
****

Posts: 1,285
Joined: Jan 2007
Reputation: 23
Post: #2
RE: Simplify php code
Include/login.php
Code:
function unset_user_login_data ($ignorePreserve = false) {
    $sql = Database::getInstance();

    if (isset($_SESSION['user_logged'])) {

        $sess_id = session_id();

        $admin_name = $_SESSION['user_logged'];

        $query = <<<SQL_QUERY
            delete from
              login
          where
              session_id = ?
          and
              user_name = ?
SQL_QUERY;

        $rs = exec_query($sql, $query, array($sess_id, $admin_name));

    }

    $preserve_list = array('user_def_lang', 'user_theme');
    $preserve_vals = array();

    if (!$ignorePreserve) {
        foreach ($preserve_list as $p) {
            if (isset($_SESSION[$p])) {
                $preserve_vals[$p] = $_SESSION[$p];
            }
        }
    }

    $_SESSION = array();

    foreach ($preserve_list as $p) {
        if (isset($preserve_vals[$p])) {
            $_SESSION[$p] = $preserve_vals[$p];
        }
    }

}
can become
Code:
function unset_user_login_data ($ignorePreserve = false) {
    $sql = Database::getInstance();

    if (isset($_SESSION['user_logged'])) {
        $sess_id = session_id();
        $admin_name = $_SESSION['user_logged'];
        $query = "DELETE FROM `login` WHERE `session_id` = ? AND `user_name` = ?";
        $rs = exec_query($sql, $query, array($sess_id, $admin_name));
    }
    $preserve_list = array('user_def_lang', 'user_theme');//may a Config::get here?
    foreach ($_SESSION as $key=>$value)
        if(!in_array($key,$preserve_list)||$ignorePreserve)
            unset($_SESSION[$key])
}
(This post was last modified: 07-01-2008 05:35 AM by sci2tech.)
07-01-2008 05:34 AM
Visit this user's website Find all posts by this user
Thread Closed 


Messages In This Thread
Simplify php code - sci2tech - 07-01-2008, 04:46 AM
RE: Simplify php code - sci2tech - 07-01-2008 05:34 AM
RE: Simplify php code - Zothos - 07-01-2008, 05:55 AM
RE: Simplify php code - sci2tech - 07-01-2008, 05:57 AM
RE: Simplify php code - xister - 07-01-2008, 06:17 AM
RE: Simplify php code - marryroy01 - 11-09-2009, 09:55 PM
RE: Simplify php code - joximu - 11-09-2009, 11:10 PM

Forum Jump:


User(s) browsing this thread: 1 Guest(s)