//aanmelden.php
<?
session_start();
echo "<font size=4>Signup</font>
<br>
<br>";
if ($_GET['action'] == 'signup') {
include("config.php");
if ($_POST['username'] == '')
{
echo "<font color=#ff0000>You didn't fill in a password did you?</font>";
}
else {
if ($_POST['email'] == '')
{
echo "<font color=#ff0000>You didn't filled in a emailadress</font>";
}
else {
if ($_POST['password'] == '')
{
echo "<font color=#ff0000>You didn't fill in a password did you?</font>";
}
else {
$pw = md5(password);
mysql_query("INSERT INTO members (username,email,password) VALUES ('$_POST[username]','$_POST[email]','$pw')")or die(mysql_error());
mail($_POST['email'], "You have registered", "Hello ".$username." You have registered on http://www.textbased.net Your nick is ".$username." and your password is ".$password."","From:
$emailadres\r\n" ."Reply-To: staff@textbased.net\r\n");
echo "You've been registered!";
}
}
}
}
else {
echo " <form action=?action=signup method=POST>
<input type=hidden name=submit value=1>
Username: <input type=text name=username maxlength=10>
<p>
Password: <input type=password name=password maxlength=15>
<p>
Email: <input type=text name=email>
<br>
<input type=submit value=Signup!>
<input type=reset value=Clear>
</form> ";
}
?>
//config.php
<?
mysql_connect('localhost', 'username', 'pass') or die(mysql_error());
mysql_select_db(db) or die(mysql_error());
$emailadres = 'jeemail';
?>
//login.php
<?
session_start();
echo "<font size=4>Login</font>
<br>
<br>";
if (isset($submit)) {
include("config.php");
if ($_POST['username'] == '') {
echo "<font color=#ff0000>You didn't fill in a username did you?!</font>";
}
else {
if ($_POST['password'] == '') {
echo "<font color=#ff0000>You didn't fill in a password did you?!</font>";
}
else {
$result = mysql_query ("SELECT * FROM members WHERE username = '".$_POST['username']."'");
$row = mysql_fetch_array($result) or die(mysql_error());
$login = "xc732mc";
$dbpass = $row['password'];
$pw = md5(password);
if ($dbpass == $pw) {
$_SESSION['username'] = $_POST['username'];
$_SESSION['dbpass'] = $dbpass;
$_SESSION['login'] = 'xc732mc';
echo "<font color=#000000>Je bent nu ingelogd</font>";
}
else {
echo "<font color=#ff0000>Wrong password</font>";
}
}
}
}
else {
echo "<form action=login.php method=POST>
Login: <input type=text name=username>
<p>
Password: <input type=password name=password>
<p>
<input type=submit name=submit value=Login>";
}
?>
//uitloggen.php
<?
include("config.php");
session_start();
if ($action == 'logout')
{
session_unset();
session_destroy();
echo "You are logged out now";
}
else
{
if ($login == 'xc732mc')
{
echo "<font size=4>Logout</font> <br>";
echo "<a href=?action=logout>Logout</a>";
}
else
{
echo "<font color=#ff0000>You aren't logged in!</font>";
}
}
?>
// Om een pagina te beveiligen zet je boven elke pagina:
<?
session_start();
if ($login == 'xc732mc')
{
je beveiligde pagina
}
else
{
Een of andere error van je bent niet ingelogd
}
?>