コード例 #1
0
ファイル: adminLogin.php プロジェクト: ashutoshSce/adminPanel
 function login($user, $pwd, $rem)
 {
     global $adminSession;
     global $adminCookieUser;
     global $adminCookiePassword;
     global $invalidUserIdOrPassword;
     $POST = array('user' => $user, 'pwd' => $pwd, 'rem' => $rem);
     $val = new validation();
     $val->addSource($POST);
     $val->addRule('user', 'string', true, 1, 35, true)->addRule('pwd', 'string', true, 1, 35, true)->addRule('rem', 'bool');
     $val->run();
     if (sizeof($val->errors) > 0) {
         $connection->close();
         $errors = implode(" <br/> ", $val->errors);
         return "Error: " . $errors;
     } else {
         $POST = $val->sanitized;
         $user = $this->escape($POST['user']);
         $pwd = $this->escape($POST['pwd']);
         $rem = $this->escape($POST['rem']);
         $adminTable = new adminTable($this->connection);
         $result = $adminTable->verifyAdminLogin($user, $pwd);
         if (is_bool($result)) {
             return $invalidUserIdOrPassword;
         } else {
             if (!isset($_SESSION)) {
                 session_start();
             }
             $_SESSION[$adminSession] = $result;
             if ($rem) {
                 setcookie($adminCookieUser, $user, time() + 10 * 365 * 24 * 60 * 60, "/");
                 setcookie($adminCookiePassword, $pwd, time() + 10 * 365 * 24 * 60 * 60, "/");
             }
             return true;
         }
     }
 }