Last active
March 6, 2018 15:13
-
-
Save i-Clyde/93c3de679031779a40f9670f1600ab19 to your computer and use it in GitHub Desktop.
Skrypt logowania bez użycia bazy danych oparty na PHP.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
if ((!isset($_POST['login'])) || (!isset($_POST['haslo']))) { | |
header('Location: index.php'); | |
exit(); } | |
require_once 'users.php'; | |
$postlog = $_POST['login']; $postlog = htmlentities($postlog, ENT_QUOTES, "UTF-8"); | |
$postpass = $_POST['haslo']; $postpass = htmlentities($postpass, ENT_QUOTES, "UTF-8"); | |
for( $x = 0; $x < 5; $x++ ) { | |
if (($user[$x] == $postlog) && ($pass[$x] == $postpass)) { | |
$logowanie = "TRUE"; | |
$login = $user[$x]; | |
break; | |
} else | |
$logowanie = "FALSE"; | |
} | |
if($logowanie == "TRUE") { | |
$_SESSION['zalogowany'] = true; | |
$_SESSION['user'] = $login; | |
unset($_SESSION['blad']); | |
header('Location: main.php'); | |
} else if ($logowanie == "FALSE") { | |
$_SESSION['blad'] = '<span style="color:red">Nieprawidłowy login lub hasło!</span>'; | |
header('Location: index.php'); | |
} else { | |
$_SESSION['blad'] = '<span style="color:red">Nieprawidłowy login lub hasło!</span>'; | |
header('Location: index.php'); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
if ((isset($_SESSION['zalogowany'])) && ($_SESSION['zalogowany']==true)) { | |
header('Location: main.php'); | |
exit(); } ?> | |
<!DOCTYPE HTML> | |
<html lang="pl"> | |
<head> | |
<meta charset="utf-8" /> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" /> | |
<link rel="stylesheet" type="text/css" href="css/style.css"> | |
<title>Logowanie.. v1</title> | |
</head> | |
<body> | |
<main> | |
<div id="container"> | |
<form action="check.php" method="post"> | |
Login: <br><input type="text" name="login" /><br> | |
Hasło: <br><input type="password" name="haslo" /><br> | |
<input type="submit" value="Zaloguj się" /> | |
</form> | |
</div> | |
</main> | |
<?php | |
if(isset($_SESSION['blad'])) echo $_SESSION['blad']; | |
unset($_SESSION['blad']); | |
?> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
session_unset(); | |
header('Location: index.php'); | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
if (!isset($_SESSION['zalogowany'])) { | |
header('Location: index.php'); | |
exit(); } | |
echo "Witaj, ".$_SESSION['user']." wyloguj się: <a href='logout.php'>tutaj!</a>"; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$user[0] = "uzyt1"; $pass[0] = "has1"; | |
$user[1] = "uzyt2"; $pass[1] = "has2"; | |
$user[2] = "uzyt3"; $pass[2] = "has3"; | |
$user[3] = "uzyt4"; $pass[3] = "has4"; | |
$user[4] = "uzyt5"; $pass[4] = "has5"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment