bin noch totaler noob in php, aber wollte einfach mal nen login erstellen
das soll erst mal der code für das eintragen der userdaten in die DB werden! aber das geht schon nicht!
dann habe ich nach einem tut. ne logme.php geschrieben
Leider stand bei dem tut nicht wie ich son login überhaupt mache und die daten dann übergebe etc. Habs halt selber mal versucht aber wie man oben sieht ohne erfolg!!
woran liegts?
PHP-Code:
<html>
<head>
<title>login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
if (nachricht == "")
{
//überprüfe benutzereingaben
$dberror ="";
$ret = in_db_einfuegen ($signupusername, $signuppassword, $emailaddress, $dberror );
if (!ret)
print "Fehler: $dberror<BR>";
else
print "Vielen Dank für die Daten";
}
else
{
global $PHP_SELF;
print "<form name=registration action=\"§PHP_SELF\" method=\"POST\">";
print " Username:";
print " <input name=\"signupusername\" type=\"text\" width=\"10\"><BR>";
print " Password:";
print " <input name=\"signuppassword\" type=\"password\" width=\"10\"><BR>";
print " Verify your password:";
print " <input name=\"signuppasswordverify\" type=\"password\" width=\"10\"><BR>";
print " Email Address:";
print " <input name=\"emailaddress\" type=\"text\" width=\"10\"><BR>";
print " <INPUT TYPE=SUBMIT VALUE=\"Sign Up\">";
print "</form>";
}
function in_db_einfuegen ($signupusername, $signuppassword, $emailaddress, &$dberror)
{
$dbhost = "localhost";
$dbuser = "admin";
$dbpassword = "admin";
$db = "community";
//überprüfen
$nachricht.="Sie müssen alle Felder ausfüllen.<BR>\n";
if ($signupusername != $signuppasswordverify)
$nachricht .= "Ich Passwort war falsch<BR>\n";
return false;
if (strlen ($signupusername) >8)
{
$nachricht .="Ich Passwort darf höchsten 8 Zeichen haben";
return false;
}
if ($nachricht = "") // Keine Fehler
{
$link= mysql_pconnect($dbhost, $dbuser, $dbpassword);
if ( !$link)
{
$dberror="Keine Verbindung zu MySQL server";
return false;
}
if (! mysql_select_db ( $db, $link) )
{
$dberror= mysql_error();
return false;
}
$anfrage= "INSERT INTO users (signupusername, signuppassword, emailaddress)
values('$username', $password', '$email')";
if ( !mysql_query ($anfrage, $link ) )
{
$dberror = mysql_error();
return false;
}
return true;
}
}
?>
</body>
</html>
dann habe ich nach einem tut. ne logme.php geschrieben
PHP-Code:
// Login und Logoute
// db login
$dbhost = "localhost";
$dbuser = "admin";
$dbpassword = "admin";
$db = "community";
$sysadminemail = "admin@localhost.com";
switch ($action) {
case login:
process_login();
die();
case logout:
//cookies null setzen
setcookie ("ck_username", "");
setcookie("ck_password", "");
setcookie("ck_user_id", "");
die();
}
function process_login() {
global $dbhost;
global $dbuser;
global $dbpassword;
global $db;
// define homepage and text variables
global $homepage;
global $homedir;
global $sysadminemail;
global $userstable;
//form vars
global $username;
global $password;
// Connecting
$link = mysql_connect("$dbhost", "$dbuser", "$dbpassword")
or die("Could not connect");
mysql_select_db("$db")
or die("Could not select database");
//usernamen und db nach existenz überprüfen
// wenn nicht error
$query = "SELECT user_id FROM imsaver_users WHERE "
. "username='$username'";
$result = mysql_query($query)
or die("Query failed at userid retrieval stage.");
//Logic concept: if the user_id doesn't exist, an empty string
// or "" will be returned with the $user_id call below.
// We can test this to see if the user has entered the username
// correctly
$num_rows = mysql_num_rows($result);
$row = mysql_fetch_array($result);
$user_id = $row[0];
//very important for user friendliness -- tell them
// what the login error was -- incorrect
// username or incorrect password
// first test -- did the username exist
if ($user_id == "") {
print "<HTML>";
print "<HEAD>";
print "<TITLE>";
print "Incorrect username";
print "</TITLE>";
print "<BODY>";
print "<CENTER>";
print "<B><CENTER>We're sorry but the username that you";
print "entered doesn't seem to exist in our database.<BR>";
print "Perhaps you entered it in error. Press the back button ";
print "to try again.";
}
else {
//this means that there was 1 result from the query so that
// username exists in the database
//now have to verify password. Basically same code.
$query = "SELECT password "
. " FROM imsaver_users "
. " WHERE username='$username'";
$result = mysql_query($query)
or die("Query failed at userid retrieval stage.");
//Encrypt the password the user entered since our
// database stores it in encrypted fashion and we need to
// compare it this way
$encryptedpassword = md5($password);
$row = mysql_fetch_array($result);
//grab the password from the row array, 0th element
// since only 1 column selected
// have to use a variable $passwordfromdb so we don't
// overwrite our $password variable from the form var
$passwordfromdb = $row[0];
if ($encryptedpassword == $passwordfromdb) {
//set our cookies for our future security checks
setcookie ("ck_username", $username);
setcookie("ck_password", $password);
setcookie("ck_user_id", $user_id);
// Create our results page showing them they are logged in
print "<HTML>";
print "<HEAD>";
print "<TITLE>";
print "You're Logged In!";
print "</TITLE>";
print "<BODY>";
print "You're Logged In";
//This needs to have a link added of course
//If you wanted to automatically take them to the main screen
// then use the header function to redirect them
print "Click Here to Continue";
print "</BODY>";
print "</HTML>";
//close the database
// Closing connection
mysql_close($link);
}
else {
//passwords didn't match so make an error page
print "<HTML>";
print "<HEAD>";
print "<TITLE>";
print "Incorrect password";
print "</TITLE>";
print "<BODY>";
print "<CENTER>";
print "<B><CENTER>We're sorry but the password that you entered";
print "doesn't match with the one in our database.<BR>";
print "Press the back button to try again.";
print "</CENTER>";
print "</BODY>";
print "</HTML>";
// Closing connection
mysql_close($link);
}
}
}
?>
Leider stand bei dem tut nicht wie ich son login überhaupt mache und die daten dann übergebe etc. Habs halt selber mal versucht aber wie man oben sieht ohne erfolg!!
woran liegts?
Kommentar