javascript - 第一次尝试无法登录

标签 javascript php jquery html mysql

我建立了一个注册和登录页面。当我注册并尝试立即登录时,它起作用了。但如果我在重新启动 XAMPP 后再次尝试,它将无法登录。 有什么建议么? 这是我的登录代码:

<?php
session_start();
if ($_SESSION["logging"] && $_SESSION["logged"])
{
    print_secure_content();
}
else
{
    if (!$_SESSION["logging"])
    {
        $_SESSION["logging"] = true;
        loginform();
    }
    else if ($_SESSION["logging"])
    {
        $number_of_rows = checkpass();
        if ($number_of_rows == 1)
        {
            $_SESSION[user] = $_GET[userlogin];
            $_SESSION[logged] = true;
            print "<h1>you have loged in successfully</h1>";
            print_secure_content();
        }
        else
        {
            print "wrong pawssword or username, please try again";
            loginform();
        }
    }
}

function loginform()
{
    print "please enter your login information to proceed with our site";
    print("<table border='2'><tr><td>username</td><td><input type='text' name='userlogin' size'20'></td></tr><tr><td>password</td><td><input type='password' name='password' size'20'></td></tr></table>");
    print "<input type='submit' >";
    print "<h3><a href='registerform.php'>register now!</a></h3>";
}

function checkpass()
{
    $servername = "localhost";
    $username = "root";
    $conn = mysql_connect($servername, $username) or die(mysql_error());
    mysql_select_db("konjam_disc", $conn);
    $sql = "select * from users where name='$_GET[userlogin]' and password='$_GET[password]'";
    $result = mysql_query($sql, $conn) or die(mysql_error());
    return mysql_num_rows($result);
}

***** 编辑 *****

这是我进入登录页面时收到的错误:

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/demo/admin/new/index.php:8) in /Applications/XAMPP/xamppfiles/htdocs/demo/admin/new/index.php on line 9

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /Applications/XAMPP/xamppfiles/htdocs/demo/admin/new/index.php:8) in /Applications/XAMPP/xamppfiles/htdocs/demo/admin/new/index.php on line 9

最佳答案

可怕的代码,并且根据缺少的内容来找到罪魁祸首,我假设您永远不会期望 $number_of_rows 高于 1

关于javascript - 第一次尝试无法登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27187919/

相关文章:

php - if 和 else 语句中 ":"的用法是什么?

javascript - 我的登录页面面临 php 验证问题

javascript - 从二维 Javascript 数组中删除一个项目

javascript - jQuery 与 DOM 性能比较

javascript - 重大事件后带走 child

javascript - 未捕获的类型错误 : Cannot set property 'value' of null with custom element

javascript - 如何在 mongoose 中使用 $set 动态更新嵌入式文档

javascript - es6 模板字符串 + 短对象文字转译失败 [gulp, babel]

php - OOP PHP 文件中的 HTML 代码

PHP如何在php中实现队列处理