簡體   English   中英

第一次在PHP中使用OOP

[英]First time with OOP in php

這是我第一次在PHP中使用一些OOP。

我已經制作了這個簡單的登錄系統,但是由於某種原因,它似乎無法正常工作。

每當我在admin_login.php頁面上輸入一些詳細信息時,它都會再次將我重定向到admin_login.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

<?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

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

?>

歡迎所有建議。

$_REQUEST['process']更改為$_REQUEST['submit'] ,然后嘗試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM