我正在制作一个登录信息表单,但表单本身的加载需要很长时间(1-2秒),所以我想知道我是否做错了什么。我也非常担心这种特殊方法的安全性。
谢谢你的任何帮助!
<?
if(isset($_POST['send']))
{
$connection=mysqli_connect('host','user','password','database');
$email=$_POST['email'];
$password=$_POST['password'];
$query=mysqli_prepare($connection,'SELECT access FROM users_table WHERE email=? AND password=?');
mysqli_bind_param($query,'ss',$email,$password);
mysqli_stmt_execute($query);
mysqli_stmt_bind_result($query,$access);
mysqli_stmt_fetch($query);
if($access>=0)
{
session_start();
$_SESSION['user_email']=$email;
$_SESSION['user_password']=$password;
$_SESSION['user_access']=$access;
switch($access)
{
case(0):
header('Location:admin page');
case(1):
header('Location:user page');
}
}
else
{
echo 'Wrong Password!';
}
mysqli_stmt_close($query);
mysqli_close($connection);
}
else
{
?>
<div id='login'>
<form method='POST' action=''>
<input name='email' type='email' placeholder='Enter your email...'>
<input name='password' type='password' placeholder='and your password.'>
<input class='button' name='send' type='submit' value='Send'>
</form>
</div>
<?
}
?>
瓶颈可能来自MySQL连接(MySQL服务器是否位于web服务器的远程位置?)
您可以通过在mysqli_connect
函数之前和之后保存时间戳(使用microtime()
),然后减去end-start得到总时间来找到这一点。
的例子:
$t = microtime(true);
// do connection here
die(microtime(true) - $t);