简体   繁体   中英

Creating a login page with no registration

I am trying to create a log in page with no registration. I tried many different ways but all I get is a blank page. My users table is as follow

id   username password group 
x      xx       xx      xx

This is my login action file:

<?php  

if ($_SERVER['REQUEST_METHOD'] =='POST')
{
        require ('php_includes/dbc_connect.php');
        require ('login_tools.php');


        list ($check, $data) =
        validate ($dbc, $_POST['username'], $_POST['password']);

        if($check)
        {
            session_start();

            $_SESSION['id'] = $data['id'];
            $_SESSION['username'] = $data['username'];
            $_SESSION['password'] =  $data['password'];

            load('Stafflogin.php');
        }
        else{ $errors = $data;}

        mysqli_close($dbc);

        include ('index31.php');


    }
?>


    <?php

function load ($page = 'index31.php')
{
    $url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
    $url = rtrim( $url,'/\\');
    $url .= '/' .$page;
    header("Location: $url");
    exit();
}

function validate($dbc ,$username = '' ,$password = '')
{
    $errors = array();
    if(empty($username))
    {$errors[] = 'Enter your username.';}
        else
        { $n = mysqli_real_escape_string($dbc, trim($username));}

        if(empty($password))
        {$errors[] = 'Enter your password.';}
        else
        {$p = mysqli_real_escape_string($dbc, trim($password));}
        if (empty($errors))
        {
            $q = " SELECT id, username, password FROM USERS WHERE username = '$n' 
            AND PASSWORD = SHA1('$p')";

            $r = mysqli_query($dbc, $q);
            if(mysqli_num_rows( $r ) == 1)
            { 
            $row = mysqli_fetch_array($r, MYSQLI_ASSOC);
        return array(true,$row);
            }
            else
            {$errors[] = 'Username and password not found.';}
            }
            return array(false,$errors);
            }


?> this is logintools.php

and the login form contains the following code on the top of the page

    if(isset($errors)&& !empty($errors))
{
    '<p id="err_msg">Oops!There was a problem:<br>';
foreach($errors as $msg)
{
    echo"- $msg<br>";
}
echo"Please try again<br></p>";
}

Can you please someone tell where I am wrong?

First of all, put this code below on top of all those scripts, to see exactly what's happening:

error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
ini_set('display_errors',1);

Then you will see where's breaking your application.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM