doutang7414 2014-11-28 11:43 采纳率: 0%
浏览 28
已采纳

首次尝试时无法登录

I had built a register and a login page. When I register and try to login immediately, it works. But if I try it again after restarting my XAMPP, it won't log in. Any suggestions? Here is my login code:

<?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);
}

****** EDIT ******

This is the error that I'm receiving when I go to the login page:

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

  • 写回答

1条回答 默认 最新

  • dtxob80644 2014-11-28 11:50
    关注

    Horrible code and based on what's all missing to find the culprit I assume you never expect $number_of_rows to be higher than 1.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错