简体   繁体   English

第一次在PHP中使用OOP

[英]First time with OOP in php

It's my first time using some OOP in PHP. 这是我第一次在PHP中使用一些OOP。

I have made this simple login system, but for some reason it doesn't seems to be working. 我已经制作了这个简单的登录系统,但是由于某种原因,它似乎无法正常工作。

Whenever I enter some details on the page admin_login.php it again redirects me to admin_login.php without saying anything. 每当我在admin_login.php页面上输入一些详细信息时,它都会再次将我重定向到admin_login.php,而无需说什么。

I'm not sure what's wrong. 我不知道怎么了。

class.admin.php class.admin.php

<?php
include 'inc/inc.functions.php';
include '..dbconnector.php';

class admin
{
    public function logged_in()
    {
        if(isset($_SESSION['adminLogged'])==1)
        {
            return true;
        }
        else
        {
            return false;
        }
    } //function

    public function login_correct($username,$password)
    {
        global $conn;
        try
        {
            $statement = $conn->prepare("SELECT * from admins where username = ? and password = ?");
            $statement->execute(
                array(
                    $username,
                    $password));
            $row=$statement->rowCount();
            if($rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        catch(PDOException $e)
        {
            echo $e->getMessage();
        }
    }//funcion
}

?>

admin_login.php admin_login.php

<?php

{
    ?>
    <table>
    <form  method="post" action="admin_process.php?process=login">
    <tr>
        <td>Username : </td>
        <td><input type="text" name="username" id="username" /></td>
    </tr>
    <tr>
        <td>Password : </td>
        <td><input type="password" name="password" id="password" /></td>
    </tr>
    <tr>
    <td><input type="submit" name="submit" value="Login"></td>
    </tr>
    </form>
    </table>
    <?php
}
?>

admin_process.php admin_process.php

<?php
session_start();
include 'class/class.admin.php';
include 'dbconnector.php';
$admin = new admin();

if(isset($_REQUEST['process']))
    {
        switch($_REQUEST['process'])
        {
            case 'login':
            $username = $_POST['username'];
            $password = $_POST['password'];
            if($admin->login_correct($username, $password))
            {   
                header('refresh:2;URL=admin_home.php');
                $_SESSION['adminLogged']=1;
                $_SESSION['adminUsername']=$username;
            }
            else
            {
                echo "Wrong username or password";
            }
            break;
            default:
            header('Location:admin_home.php');
        }
    }
    else
    {
        header('Location:admin_home.php');
    }

?>

All suggestions are welcome. 欢迎所有建议。

$_REQUEST['process']更改为$_REQUEST['submit'] ,然后尝试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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