<?php
if(empty($_POST) AND
$_SESSION['logged_in'] !== true) die("Aby się zalogować musisz podać poprawne dane!"); try
{
$conn = new PDO('mysql:host=host_bazy;dbname=nazwa_bazy', 'user', 'pass');
$stmt = $pdo->prepare('SELECT `user`, `pass` FROM `users` WHERE
`user`=:user AND
`passwd`=:passwd);');
$stmt->bindValue(':user', @$_POST['user'], PDO::PARAM_STR);
$stmt->bindValue(':passwd', hash('sha256', @$_POST['passwd']), PDO
::PARAM_STR); if(count($stmt->execute()) == 1) $_SESSION['logged_in'] = true;
$stmt->closeCursor();
} // End try
catch(PDOException $e)
{
echo 'Błąd:'.$e->getMessage();
} // End catch
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://w...content-available-to-author-only...3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Logowanie z użyciem plików tekstowych</title>
</head>
<body>
<?php
if($_SESSION['logged_in'] === true)
echo 'Brawo! Masz dostęp do tych danych. :)';
else
echo 'Brak dostępu!';
?>
</body>
</html>
PD9waHAKIAlzZXNzaW9uX3N0YXJ0KCk7CiAJIGlmKGVtcHR5KCRfUE9TVCkgQU5EICRfU0VTU0lPTlsnbG9nZ2VkX2luJ10gIT09IHRydWUpCiAJCWRpZSgiQWJ5IHNpxJkgemFsb2dvd2HEhyBtdXNpc3ogcG9kYcSHIHBvcHJhd25lIGRhbmUhIik7CgkgdHJ5Cgl7CgkJJGNvbm4gPSBuZXcgUERPKCdteXNxbDpob3N0PWhvc3RfYmF6eTtkYm5hbWU9bmF6d2FfYmF6eScsICd1c2VyJywgJ3Bhc3MnKTsKCQkkc3RtdCA9ICRwZG8tPnByZXBhcmUoJ1NFTEVDVCBgdXNlcmAsIGBwYXNzYCBGUk9NIGB1c2Vyc2AgV0hFUkUgCgkJCWB1c2VyYD06dXNlciBBTkQKCQkJYHBhc3N3ZGA9OnBhc3N3ZCk7Jyk7CgkJJHN0bXQtPmJpbmRWYW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