download2014711 2014-03-18 19:32
浏览 53
已采纳

慢PHP登录表单

I am making a login information form but the loading of the form itself takes a long time (1-2 sec), so I am wondering if I am doing something wrong. I am also very worried about the security of this particular approach.

Thanks for any help whatsoever!

<?
        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>
            <?
        }
    ?>
  • 写回答

1条回答 默认 最新

  • duanpacan9388 2014-03-18 19:34
    关注

    The bottleneck is probably from the MySQL connection (is the MySQL server located remotely from the web server?)

    You can find this out by saving a timestamp (using microtime()) before and after the mysqli_connect function, then subtracting end-start to get the total time.

    Example:

    $t = microtime(true);
    // do connection here
    die(microtime(true) - $t);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错