<?php
session_start();
$verhalten = 0;
//Datenbank parameter [loc -> location]
$db_name = "htmlworld";
$db_pass = "420jedentag";
$db_user = "default";
$db_loc = "localhost"
//Create SQL connection
$connect = mysqli_connect($db_loc, $db_user, $db_pass, $db_name);
//Check connection
if (mysqli_connect_errno($connect)){
echo 'Failed to connect to database:<br>'.mysqli_connect_error();
}
if(!isset($_SESSION["username"]) and !isset($_GET["page"])){
$verhalten = 0;
}
if(isset($_GET["page"])){
if($_GET["page"] == "log"){
$user = $_POST["user"];
$passwort = $_POST["passwort"];
if($user == "cannabis" and $passwort == "viel"){
$_SESSION["username"] = $user;
$verhalten = 1;
}else{
$verhalten = 2;
}
}
}
?>
<html lang="de">
<head>
<title>Login</title>
<?php
if($verhalten == 1){
?>
<meta http-equiv="refresh" content="3; URL=seite2.php" />
<?php
}
?>
</head>
<body>
<?php
if($verhalten == 0){
?>
Bitte logge dich ein:<br />
<form method="post" action="index.php?page=log">
Username:<input type="text" name="user" /><br />
Passwort:<input type="password" name="passwort" /><br />
<input type="submit" value="Einloggen" />
</form>
<p><a href="register.php">Du bist noch nicht dabei? Hier registrieren!</a></p>
<?php
}
if($verhalten == 1){
?>
Du hast dich erfolgreich eingeloggt und wirst nun weitergeleitet...!
<?php
}
if($verhalten == 2){
?>
Du hast dich nicht richtig eingeloggt.<br><a href="index.php">Zurück</a>
<?php
}
?>
</body>
</html>
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.