Advertisement
rav1989

Untitled

Apr 25th, 2011
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.17 KB | None | 0 0
  1. <?php
  2. try{
  3.     ob_start();
  4.     require('../class/sesja.php');
  5.  
  6.     if($session -> getUser() -> isAnonymous())
  7.     {
  8.  
  9.         if($_SERVER['REQUEST_METHOD'] == 'POST')
  10.         {
  11.             // Dane przyszly z formularza, czas je sprawdzic
  12.             $result = User::Sprawdz($_POST['login'], $_POST['haslo']);
  13.  
  14.             if($result instanceof user)
  15.             {
  16.                 $session -> Update($result);
  17.                 echo 'Dziekujemy, zostales zalogowany jako '.
  18.                 $session -> getUser() -> getNazwa().'.
  19.                     <a href="./index.php">Powrot</a>';
  20.             }
  21.             else
  22.             {
  23.                 echo 'Nieprawidlowy login i/lub haslo!';
  24.             }
  25.         }
  26.         else
  27.         {
  28.             echo '<form method="post" action="./login.php">
  29.                 Login: <input type="text" name="login"/><br/>
  30.                 Haslo: <input type="password" name="haslo"/><br/>
  31.                 <input type="submit" value="Zaloguj"/>         
  32.                 </form>';      
  33.         }
  34.     }
  35.     else
  36.     {
  37.         // Jezeli plik ten odpalony przez osobe zalogowana,
  38.         // to ja wylogowujemy
  39.         if($_GET['action'] == 'logout')
  40.         {
  41.             $session -> update(new user(true));
  42.             header('Location: ./index.php');
  43.         }else{
  44.             header('Location: ./index.php');
  45.             exit;
  46.         }
  47.     }
  48.     ob_end_flush();
  49. }
  50. catch(PDOException $exception)
  51. {
  52.     echo 'Blad bazy danych: '.$exception->getMessage();
  53. }
  54. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement