Пример #1
0
 public function indexAction()
 {
     $request = new Yaf_Request_Http();
     if ($request->isGet()) {
         return;
     }
     if ($request->isPost()) {
         $post = $request->getPost();
         $username = $post['username'];
         $password = $post['password'];
         if ($username == 'admin' && $password == 'admin') {
             Yaf_Session::getInstance()->offsetSet('username', $username);
             $this->redirect("Admin");
             // 跳转到login Actios->forward("login", array("from" => "Index")); // 跳转到login Action
             return FALSE;
         } else {
             $password = md5($password);
             $sql = 'SELECT * FROM user WHERE username=:username AND password=:password';
             $stmt = $this->dbo->prepare($sql);
             $stmt->bindValue(':username', $username);
             $stmt->bindValue(':password', $password);
             $stmt->execute();
             $rows = $stmt->fetch();
             if (empty($rows)) {
                 echo "用户名或密码错误";
             } else {
                 Yaf_Session::getInstance()->offsetSet('username', $username);
                 Yaf_Session::getInstance()->offsetSet('userid', $rows['id']);
                 $this->redirect('Admin');
                 return;
             }
         }
         exit;
     }
 }
Пример #2
0
 /**
  * 获取传递的参数
  * @param string $key key
  * @param bool|false $flag 是否返回原始数据
  * @param array $unset 需要清除的参数
  * @return array|string 返回获取到的值
  */
 public function getParam($key = '', $flag = false, $unset = array())
 {
     $yafHttp = new Yaf_Request_Http();
     if ($yafHttp->isGet()) {
         $array = $yafHttp->getQuery();
         if ($key != '') {
             $array = $array[$key];
         }
     } else {
         if ($key != '') {
             $array = $yafHttp->getPost($key);
         } else {
             $array = $yafHttp->getPost();
             $arrayTem = $yafHttp->getQuery();
             $array = array_merge($array, $arrayTem);
         }
     }
     if (count($unset) > 0) {
         foreach ($unset as $key) {
             unset($array[$key]);
         }
     }
     if ($flag) {
         return $array;
     }
     $tem = array();
     if (count($array) > 0 && is_array($array)) {
         foreach ($array as $key => $val) {
             $tem[$key] = is_array($val) ? $val : addslashes(strip_tags($val));
         }
     } else {
         $tem = !empty($array) ? addslashes(strip_tags($array)) : '';
     }
     return $tem;
 }