4 changed files with 99 additions and 0 deletions
@ -0,0 +1,29 @@ |
|||||
|
<?php |
||||
|
session_start(); |
||||
|
require("init.php"); |
||||
|
$username = $_POST["username"]; |
||||
|
$password = $_POST["password"]; |
||||
|
|
||||
|
//příprava k zobrazení dat |
||||
|
$sql = "SELECT * FROM users WHERE |
||||
|
username='$username' AND password='$password'"; |
||||
|
$result = mysqli_query($conn,$sql); |
||||
|
|
||||
|
//zjištění jestli uživatel existuje |
||||
|
if (mysqli_num_rows($result) == 1) { |
||||
|
$row = mysqli_fetch_assoc($result); |
||||
|
|
||||
|
//"zapsání uživatele do paměti" (vytvoření session pro jméno) |
||||
|
$_SESSION["username"] = $row["username"]; |
||||
|
$_SESSION["id"] = $row["id"]; |
||||
|
|
||||
|
//přesměrování na hl.stráku |
||||
|
header("Location: /?login=1"); |
||||
|
} else { |
||||
|
header("Location: /?error=1"); |
||||
|
//error 1 = uživatel nenalezen |
||||
|
} |
||||
|
|
||||
|
|
||||
|
|
||||
|
?> |
@ -0,0 +1,25 @@ |
|||||
|
<?php |
||||
|
session_start(); |
||||
|
if(!isset($_SESSION["username"])){ |
||||
|
header("Location: /?error=2"); |
||||
|
} |
||||
|
|
||||
|
?> |
||||
|
<!DOCTYPE html> |
||||
|
<html lang="en"> |
||||
|
<head> |
||||
|
<meta charset="UTF-8"> |
||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
||||
|
<title>Document</title> |
||||
|
</head> |
||||
|
<body> |
||||
|
<p> |
||||
|
<?php |
||||
|
echo "Vítej uživatel:". $_SESSION["username"]; |
||||
|
?> |
||||
|
</p> |
||||
|
|
||||
|
<a href="logout.php">LOGOUT</a> |
||||
|
</body> |
||||
|
</html> |
@ -0,0 +1,39 @@ |
|||||
|
<?php |
||||
|
session_start(); |
||||
|
?> |
||||
|
<!DOCTYPE html> |
||||
|
<html lang="en"> |
||||
|
<head> |
||||
|
<meta charset="UTF-8"> |
||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"> |
||||
|
<title>Login system</title> |
||||
|
</head> |
||||
|
<body> |
||||
|
<h1>Login</h1> |
||||
|
<form action="auth.php" method="post"> |
||||
|
<input type="text" name="username" id="username" placeholder="Username"> |
||||
|
<input type="password" name="password" id="password" placeholder="Password"> |
||||
|
<input type="submit" value="Login"> |
||||
|
</form> |
||||
|
|
||||
|
<?php |
||||
|
//zjištění stavů a jejich "zpětná vazba" |
||||
|
if(isset($_SESSION["username"])){ |
||||
|
echo "<p>Přihlášený uživatel:". $_SESSION["username"]."</p>"; |
||||
|
echo "<a href=\"logout.php\">LOGOUT</a>"; // \" escape uvozovek pro odkaz |
||||
|
} |
||||
|
if(isset($_GET["error"])){ |
||||
|
echo "<p>Error ". $_GET["error"]. "</p>"; |
||||
|
} |
||||
|
if(isset($_GET["login"])){ |
||||
|
echo "<p>Uživatel byl přihlášen</p>"; |
||||
|
} |
||||
|
if(isset($_GET["logout"])){ |
||||
|
echo "<p>Uživatel byl odhlášený</p>"; |
||||
|
} |
||||
|
|
||||
|
?> |
||||
|
|
||||
|
</body> |
||||
|
</html> |
@ -0,0 +1,6 @@ |
|||||
|
<?php |
||||
|
session_start(); |
||||
|
session_unset(); |
||||
|
session_destroy(); |
||||
|
header("Location: /?logout=1"); |
||||
|
?> |
Loading…
Reference in new issue