Christoph Burghardt

 Start   

Passwortschutz und Benutzerverwaltung mit Hilfe
einer MySQL-Datenbank


config.php


<?php
$server= "localhost";
$user= "root";
$passwort= "root";
$datenbank= "xy";
$verbindung= mysql_connect ($server, $user, $passwort) or die ("Es konnte keine
Verbindung zum Server hergestellt werden.");
mysql_select_db ($datenbank) or die ("Die Datenbank existiert nicht.");

?>


tabelleanlegen.php

<?php
include ('config.php');
$a= mysql_query("create table benutzer (
id int (10) not null auto_increment,
benutzer text not null,
passwort text not null,
email text not null,
name text not null,
primary key (id)
) type=myisam; ");

?>


anmelden.php

<html>
<head>
<title>
Formular für die Dateneingage Anmeldung
</title>
</head>

<body>

<table width="350" align="center">

<form action="http://localhost/anmelden.php" method="POST">

<tr>
<td>

Benutzername<br><input type="text" name="benutzer">

</td>
</tr>

<tr>
<td>

Passwort<br><input type="text" name="passwort">

</tr>
</td>

<tr>
<td>

Email<br> <input type="text" name="email">

</tr>
</td>

<tr>
<td>

Name <br><input type ="text" name="name">

</td>
</tr>

<tr>
<td>
<br>
<input type="submit" value="absenden">

</tr>
</td>

</form>
</table>
</body>
</html>

<?php
include ('config.php');
$e= $_POST["benutzer"];
$f= $_POST["passwort"];
$g= $_POST["email"];
$h= $_POST["name"];

if (!$e or !$f or !$g or !$h)

{

}

else

{

$y = "insert into benutzer (benutzer, passwort, email, name) values ('$e','$f','$g','$h')";
$z= mysql_query($y);

}


?>


einloggen.php

<html>
<head>
<title>
Registrierung
</title>
</head>

<body>
<table width="350" align="center">

<form action="http://localhost/pruefen.php" method="POST" >

<tr>
<td>

Benutzer<br>
<input type="text" size="30" name="benutzer">

</td>
</tr>

<tr>
<td>

Passwort<br>
<input type="password" size="30" name="passwort">

</td>
</tr>

<tr>
<td>

<input type="submit" value="jetzt einloggen">

</tr>
</td>

</table>
</form>
</body>
</html>


pruefen.php

<?php
include ('config.php');
$benutzer= $_POST['benutzer'];
$passwort= $_POST['passwort'];

$a= mysql_query ("select passwort from benutzer where benutzer='$benutzer' ");

$c= mysql_fetch_row($a);

if (!$passwort)

{

header("Location:http://localhost/einloggen.php");
exit; // nachfolgender Code wird nicht ausgeführt

}

else

{

if ($passwort==$c[0])

{

echo "Eingabe erfolgreich";

}

else

{

header("Location:http://localhost/einloggen.php");
exit; // nachfolgender Code wird nicht ausgeführt

}

}

?>