Login Script lädt zu langsam

Status
Nicht offen für weitere Antworten.

memo12

Mitglied
Hallo,
Ich habe ein LOGIN script aus dem I-Net, das Problem ist das dieser Script nun Sehr lange braucht um zu laden (30 sec)


Kann ich das irgendwie verschnellern?



Quellcode:

PHP:
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>Acery World...Die Community für Gamer,Programmierer und
Grafiker</title>
<style type="text/css">

body, html {
height:100%;
}

body {
background-color:#86c9ef;
background-image:url('http://acery-web.cwsurf.de/images/bb_1.png');
background-position:center;
background-repeat:no-repeat;
}
</style>
</head>
<body
style="margin-top: 0px; height: 546px; margin-left: 144px; width: 716px;">
<br>
&nbsp;&nbsp; <img style="width: 200px; height: 55px;" alt="Acery World"
src="http://acery-web.cwsurf.de/images/logo.png"><br>
&nbsp;&nbsp;&nbsp;<span style="color: rgb(102, 102, 102);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span
style="font-family: Arial; color: rgb(102, 102, 102);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Home&nbsp;&nbsp;&nbsp; Games&nbsp;&nbsp;&nbsp; News&nbsp;&nbsp;&nbsp;
Chat&nbsp;&nbsp;&nbsp; Tutorials</span>&nbsp;&nbsp; <span
style="color: rgb(102, 102, 102); font-family: Arial;">Uploader</span><br
style="color: rgb(153, 153, 153); font-family: Arial;">
<br>
<?php
session_start();
// Check if he wants to login:
if (!empty($_POST[username]))
{
	require_once("connect.php");

	// Check if he has the right info.
	$query = mysql_query("SELECT * FROM members
							WHERE username = '$_POST[username]'
							AND password = '$_POST[password]'")
	or die ("Error - Couldn't login user.");
	
	$row = mysql_fetch_array($query)
	or die ("Error - Couldn't login user.");
	
	if (!empty($row[username])) // he got it.
	{
		$_SESSION[username] = $row[username];
		echo "Welcome $_POST[username]! You've been successfully logged in.";
		exit();
	}
	else // bad info.
	{
		echo "Error - Couldn't login user.<br /><br />
			Please try again.";
		exit();
	}
}

?>




<form action="login.php" method="post">
			<table width="75%" border="1" align="center" cellpadding="3" cellspacing="1">
				<tr>
					<td width="100%"><h5>Login</h5></td>
				</tr>
				<tr>
					<td width="100%"><label>Username: <input type="text" name="username" size="25" value="<? echo $_POST[username]; ?>"></label></td>
				</tr>
				<tr>
					<td width="100%"><label>Password: <input type="password" name="password" size="25" value=""></label></td>
				</tr>
				<tr>
					<td width="100%"><input type="submit" value="Login!"></td>
				</tr>
			</table>
		</form>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<form action="non" name="footer"><span
style="color: rgb(102, 102, 102); font-family: Arial;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<small>
<small>©2010-2011 Acery Web </small></small></span><b
style="color: rgb(102, 102, 102); font-family: Arial;"><small><small>Alle
Rechte vorbehalten</small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Kontakt&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a
style="color: rgb(102, 102, 102);" href="impressum.html">Impressum</a>
</b></form>
</body>
</html>


Danke
LG
 
Am PHP-Code fällt mir eigentlich nichts auf bezüglich der Geschwindigkeit.
Werden denn irgendwelche Fehler/Warnungen ausgegeben?
Eine müsste mindestens wegen [phpf]session_start[/phpf] kommen, denn diese wird nach einer Ausgabe aufgerufen.

Du könntest noch ein 'LIMIT 1' im SQL-Query hinzufügen, aber das erzeugt bestimmt nicht die 30 Sekunden!


Aber was die Sicherheit angeht, ist der Code ziemlich unsicher!
Dieser verwendet die $_POST-Variablen 'username' und 'password' einfach so im SQL-Query. Man muss die vorher escapen (Anführungszeichen, ... maskieren), damit kein schädlicher Code ausgeführt werden kann:


PHP:
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$query = mysql_query("SELECT * FROM members 
                            WHERE username = '$username' 
                            AND password = '$password'");
Auch im [phpf]echo[/phpf] sowie im HTML-Quelltext verwendest du einfach diese Variable!
PHP:
/* Unsicher */
echo "Welcome $_POST[username]! You've been successfully logged in.";
<input type="text" name="username" size="25" value="<? echo $_POST[username]; ?>">
/* Sicher */
echo "Welcome ". htmlspecialchars($username, ENT_QUOTES) . "! ...";
<input type="text" name="username" size="25" value="<? echo htmlspecialchars($username, ENT_QUOTES) ?>">
Zusätzlich würde ich dir empfehlen die Indizes in Array-Zugriffen in Anführungszeichen zu schreiben.
 
Hallo,
Ich habe auserversehen den fehler gemacht und die Variablen im HTML Code eingetragen, dies war nicht nötig, ich musste eigentlich nur die FOrm einfügen und den rest in die Login.php.

wen die nur noch die Form im HTML steht ist es dan sicher?


Danke
LG
 
Wähe das sicher:

HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
  
  <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
  <title>Jetzt Kostenlos Anmelden</title>

  
  
  <style type="text/css">

body, html {
height:100%;
}

body {
background-color:#86c9ef;
background-image:url('http://acery-web.cwsurf.de/images/bb_1.png');
background-position:center;
background-repeat:no-repeat;
}
  </style>
</head><body style="margin-top: 0px; height: 546px; margin-left: 144px; width: 716px;">
<br>

&nbsp;&nbsp; <img style="width: 200px; height: 55px;" alt="Acery World" src="http://acery-web.cwsurf.de/images/logo.png"><br>

&nbsp;&nbsp;&nbsp;<span style="color: rgb(102, 102, 102);">&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="font-family: Arial; color: rgb(102, 102, 102);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Home&nbsp;&nbsp;&nbsp; Games&nbsp;&nbsp;&nbsp; News&nbsp;&nbsp;&nbsp;
Chat&nbsp;&nbsp;&nbsp; Tutorials</span>&nbsp;&nbsp; <span style="color: rgb(102, 102, 102); font-family: Arial;">Uploader<br style="color: rgb(153, 153, 153); font-family: Arial;">
</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="http://acery-web.cwsurf.de/images/icons/mail.png" alt="Mail" border="0" height="64" width="64">
<img src="http://acery-web.cwsurf.de/images/icons/user.png" alt="User" border="0" height="64" width="64"><img src="http://acery-web.cwsurf.de/images/icons/comment.png" alt="Comment" border="0" height="64" width="64"><img src="http://acery-web.cwsurf.de/images/icons/erde.png" alt="Erde" border="0" height="64" width="64"><img src="http://acery-web.cwsurf.de/images/icons/download.png" alt="Download" border="0" height="64" width="64">&nbsp;&nbsp;&nbsp;<span style="color: rgb(102, 102, 102); font-family: Arial;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</span><br>

<form action="register.php" method="post">
  <table align="center" border="1" cellpadding="3" cellspacing="1" width="75%">
    <tbody>
      <tr>
        <td width="100%">
        <h5><span style="color: rgb(102, 102, 102); font-family: Arial;">Jetzt
Kostenlos Anmelden</span><br>
        </h5>
        </td>
      </tr>
      <tr style="color: rgb(102, 102, 102); font-family: Arial;">
        <td width="100%"><label>Gewünschter
Username:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input name="username" size="25" value="&lt;? echo $_POST[username]; ?&gt;" type="text"></label></td>
      </tr>
      <tr style="color: rgb(102, 102, 102); font-family: Arial;">
        <td width="100%"><label>Vorname:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input name="firstname" size="25" value="&lt;? echo $_POST[firstname]; ?&gt;" type="text"></label></td>
      </tr>
      <tr style="color: rgb(102, 102, 102); font-family: Arial;">
        <td width="100%"><label>Nachname:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input name="lastname" size="25" value="&lt;? echo $_POST[lastname]; ?&gt;" type="text"></label></td>
      </tr>
      <tr style="color: rgb(102, 102, 102); font-family: Arial;">
        <td width="100%"><label>Passwort:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input name="password" size="25" value="&lt;? echo $_POST[password]; ?&gt;" type="password"></label></td>
      </tr>
      <tr style="color: rgb(102, 102, 102); font-family: Arial;">
        <td width="100%"><label>Passwort
Wiederholen:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <input name="password2" size="25" value="" type="password"></label></td>
      </tr>
      <tr>
        <td width="100%"><input value="Anmelden!" type="submit"></td>
      </tr>
    </tbody>
  </table>
</form>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span style="color: rgb(204, 0, 0); font-weight: bold; font-family: Arial;">ACHTUNG:</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<span style="font-weight: bold; font-family: Arial;"><span style="color: rgb(102, 102, 102);">Derzeit Gibt es Probleme mit dem Design bzw bei maschen wird &lt;?echo $_POST... <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Angezeigt, Diesen Eintrag kann einfach entfernen und die richtigen daten hingeschrieben<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; werden, lesen sie mehr unter NEWS<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Vielen Dank Ihr Acery Web (World) Team<br>
</span></span>
<br>

<br>

<form action="non" name="footer"><span style="color: rgb(102, 102, 102); font-family: Arial;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<small> <small>©2010-2011 Acery Web </small></small></span><b style="color: rgb(102, 102, 102); font-family: Arial;"><small><small>Alle
Rechte vorbehalten</small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Kontakt&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a style="color: rgb(102, 102, 102);" href="impressum.html">Impressum und
AGB</a> </b></form>

</body></html>

danke
LG
 
Bitte nutze statt den QUOTE-Tags lieber die HTML-Tags ([code=html]Code[/code]).

Zu deiner Frage:
Überlege doch bitte mal selbst: Gebe ich externe Variablen (Forumlar-Daten) aus?
In deinem Code ist das so. Du gibst in jedem value-Attribut den per POST übergebenen Wert aus.

Ich würde dir empfehlen, diese Werte erstmal aus Existenz zu prüfen ([phpf]isset[/phpf]) und danach auch noch per [phpf]htmlspecialchars[/phpf] zu escapen.

Du kannst auch mal einen Blick in mein Tutorial werfen: Sicherheit in PHP-Codes schaffen
 
Status
Nicht offen für weitere Antworten.

Neue Beiträge

Zurück