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 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行