Code
Also hier mein Code Beispiel:
SQL-Code:
PHP-Code (DB-Verbindung[Dateiname: db.inc.php])
PHP-Login (index.php)
PHP-Logout (logout.php)
So jetzt mal viel Spass beim ausprobieren.
lg Roger
Also hier mein Code Beispiel:
SQL-Code:
Code:
CREATE TABLE login
(
log_id int(4) NOT NULL AUTO_INCREMENT,
log_name varchar(32),
log_password varchar(49),
CONSTRAINT PK_login PRIMARY KEY (log_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO login (log_name, log_password)
VALUES ('user', '123asd');
Code:
<?php
$sql['host'] = "localhost";
$sql['user'] = "root;
$sql['passwort'] = "";
$sql['db'] = "[login]"; /* Datenbankname */
if (mysql_connect ($sql['host'], $sql['user'], $sql['passwort']))
{
if (!mysql_select_db ($sql['db']))
{
echo "<p>Datenbank konnte nicht ausgewählt werden.</p>";
}
}
else
{
echo "<p>Verbindung konnte nicht hergestellt werden!</p>";
}
?>
Code:
<?php
/* Vor Beenden der Session wieder aufnehmen */
session_start();
include "db.inc.php";
/* Falls Aufruf von der Login Seite */
if (isset($_POST['submit']))
{
$log_name = $_POST['log_name'];
$log_password = $_POST['log_password'];
$result = mysql_query("
SELECT log_name, log_password
FROM login
WHERE log_name = '$log_name'");
if(mysql_fetch_row($result) > 0)
{
$db_name = mysql_result($result, 0, 'log_name');
$db_password = mysql_result($result, 0, 'log_password');
}
else
{
$db_name = "";
$db_password = "0";
}
/* Falls Name und Passwort korrekt*/
if($log_name == $db_name && $log_password == $db_password)
{
$_SESSION['log_name'] = $log_name;
$_SESSION['log_password'] = $log_password;
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
****************************
* Design and *
* Programming by *
* xxxxxxxxxxxxxxxxxxxxx *
* xxxxxxxxxxxxxxxxxxxxx *
****************************
//-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
<head>
<title>Login</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<meta http-equiv="content-language" content="de, at" />
<meta http-equiv="pragma" content="no-cache" />
<meta name="design" content="*" />
<meta name="author" content="*" />
<meta name="date" content="2008-04-12" />
<meta name="description" content="*" />
<meta name="keywords" content="*" />
<meta name="robots" content="index" />
<meta name="robots" content="follow" />
<meta name="revisit-after" content="30 days" />
</head>
<body>
<!-- Anfang Login -->
<div id="login">
<?php
if (isset($_SESSION['log_name']))
{
echo '<table class="login" border="0" cellpadding="2" cellspacing="2">';
echo '<tr>';
echo '<td><a href="logout.php" class="in">Logout >></a></td>';
echo '</tr>';
echo '</table>';
}
else
{
echo '<form name="login" action="index.php?in_id=10" method="post" onsubmit="return checkform()">';
echo '<table class="login" border="0" cellpadding="2" cellspacing="2">';
echo '<tr>';
echo '<td class="weiss">Login</td>';
echo '<td><input type="text" name="log_name" maxlength="32" size="10" class="aus" /></td>'; /* Datei zum ausloggen */
echo '</tr>';
echo '<tr>';
echo '<td class="weiss">Passwort</td>';
echo '<td><input type="password" name="log_password" maxlength="40" size="10" class="aus" /></td>';
echo '</tr>';
echo '<tr>';
echo '<td> </td>';
echo '<td class="weiss"> <input type="submit" name="submit" value=">>" class="in" /></td>';
echo '</tr>';
echo '</table>';
echo '</form>';
}
?>
</div>
<!-- Ende Login -->
</body>
</html>
Code:
<?php
session_start();
session_destroy();
header ('Location: index.php');
?>
lg Roger