Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.86 KB | None | 0 0
  1. to wszystko jest w PHP
  2.  
  3. app to jest obiek
  4.  
  5. $app->post().. to wywołanie funkcji
  6.  
  7. isset()  empty() to jakie wbudowane funkcje php
  8.  
  9. $ tworzy zmienne
  10.  
  11.  
  12. $app->post('/login', function ($request, $response, $args) {
  13.     $sid = session_id();
  14.     $login =$_POST['login'];
  15.     $password =$_POST['password'];
  16.     $user = Users::where('name', $login)->where('password', md5($password))->first();
  17.     if(isset($user) && !empty($user) ){
  18.         $_SESSION["user"] = $login;
  19.         if($user->admin == 1){
  20.             $_SESSION["admin"]=1;
  21.         }
  22.         $sess = new Ses();
  23.         $sess->userId = $user->id;
  24.         $sess->id = $sid;
  25.         $sess->save();
  26.         return $response->withStatus(200)->withHeader('Location', '/');
  27.     }else{
  28.         $args['login_error']=true;
  29.         return $this->renderer->render($response, 'login.phtml', $args);
  30.     }
  31.  
  32.  
  33. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement