- login.php - procedura logowania
- form.php - formularz logowania
- main.php - strona dostępna po zalogowaniu
- logout.php - procedura wylogowania
- passwords.txt - plik przechowujący dane logowania
login.php
<?php function checkPass($user, $pass) { $result = 2; if($arr[0] != $user) continue; if($arr[1] == $pass){ $result = 0; } break; } return $result; } } $_SESSION['komunikat'] = "Wprowadź nazwę i hasło użytkownika."; include('form.php'); } else{ $val = checkPass($_POST["user"], $_POST["haslo"]); if($val == 0){ $_SESSION['zalogowany'] = $_POST["user"]; } else if($val == 1){ $_SESSION['komunikat'] = "Błąd serwera. Zalogowanie nie było możliwe."; include('form.php'); } else{ $_SESSION['komunikat'] = "Błąd serwera. Zalogowanie nie było możliwe."; include('form.php'); } } ?>
form.php
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Logowanie</title> </head> <body> <div> <div style="font-size:16pt"> <?php else ?> </div> <form action = "login.php" methood = "POST"> <table> <tr> <td>Użytkownik:</td> <td> <input type="text" name="user"> </td> </tr> <tr> <td>Hasło:</td> <td> <input type="password" name="haslo"> </td> </tr> <tr> <td colspan="2" style="text-align:center;"> <input type="submit" value="Zaloguj"> </td> </tr> </table> </form> </div> </body> </html>
main.php
<?php $_SESSION['komunikat'] = "Nie jesteś zalogowany!"; include('form.php'); } ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Lista plików</title> </head> <body> <br /> <a href="logout.php">Wyloguj</a> </body> </html>
logout.php
<?php $komunikat = "Nie jesteś zalogowany!"; } else{ $komunikat = "Wylogowanie prawidłowe!"; } ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Wylogowanie</title> </head> <body> </body> </html>
passwords.txt
admin:qwerty