Quantcast
Channel: WampServer - WampServer English
Viewing all articles
Browse latest Browse all 3177

twenty second reponse time for a very simply PHP MySQL combination (2 replies)

$
0
0
I've got a default installation of WAMP, I haven't made any optional changes to the configuration.

I have a very simple "application" which

- user fills in a login form and submits it
- PHP code gets user's password from DB
- hashs - SHA256 - the user's password input
- compares the hashed password and the hashed password from the DB and outputs a Correct or Not Correct message via echo

When I click the submit form it takes takes 20 seconds to get a response back.

I seem to remember seeing a post like this before but I can't find it.

The HTML/PHP involved is small, so I'm going to show it below. This works properly but takes forever. Also, yes, I've done no input sanitizing - I'm just learning to use MySQL from PHP. I will add the best security I can as I go along. These are just my first small steps:

HTML file with login form:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[www.w3.org];
<html xmlns="[www.w3.org];

<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>
<body>
<p>Please Login</p>
<form method="post" action="[justblog];
<p><input name="userName" type="text" /></p>
<input name="password" type="text" />
<input name="Submit1" type="submit" value="submit" />
</form>
</body>
</html>


Login processing HTML/PHP file

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[www.w3.org];
<html xmlns="[www.w3.org];
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>
<body>
<?php
$link = mysqli_connect("localhost", "root", "", "justblog" ) ;
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
else {
// Attempt select query execution
$sql = 'SELECT * FROM jb_users WHERE userName="' . $_POST['userName'] . '"';
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
$row = mysqli_fetch_array($result);
$hashed = hash('sha256', $_POST['password']);
if ($hashed == $row['password']) {
echo $row['userName'] . ' Password is Correct<br>';
}
else {
echo $row['userName'] . ' <b>Password is INCORRECT</b><br>';
}
// Close result set
mysqli_free_result($result);
}
else{
echo "No records matching your query were found.";
}
}
else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
}
mysqli_close($link);
?>
</body>
</html>


I just timed another try and it went 26 seconds.

Can anyone suggest any configuration changes that will make this bloody thing respond in a reasonable time - like a fraction of a second?

Viewing all articles
Browse latest Browse all 3177

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>