admin管理员组

文章数量:1122832

I'm setting up the primary files for a user management system. I'm following the steps for a tutorial I found on YouTube.

I've come across a problem. In index.php I've set up things so that you get sent to a login screen if the GET variable isn't set or is empty. If it's not empty or unset, then there are other conditions to either show a specific view, default to the login page, or return a 404 error.

The problem is that when I enter the URL index.php?view=home, I should see:

  • The navbar
  • The contents of home.php
  • There's also a JS script for toggling the navbar (I'm using Bulma CSS).

Instead, what I get is a 404 error. Inputting index.php?view=login indeed takes me to the login screen, so I'm not sure what's wrong with home specifically.

Here's the contents of index.php (you can also see the repo here:

<?php require "./inc/session_start.php"; ?>

<!DOCTYPE html>
<html lang="en">
<head>
    <?php
        # HTML header
        include "./inc/head.php";
    ?>
</head>
<body>
    <?php
        if ( !isset( $_GET["view"] ) || $_GET["view"] == "" ) {
            $_GET["view"] = "login";
        }

        # Display views that exist and aren't "login" nor "404"
        if ( is_file("./view" . $_GET["view"] . ".php") && $_GET["view"] != "login" &&  $_GET["view"] != "404" ) {
            include "./inc/navbar.php";
            # Load current view
            include "./views" . $_GET["view"] . ".php";
            include "./inc/navbar_toggle_script.php";
        } else {
            if ( $_GET["view"] == "login" ) {
                include "./views/login.php";
            } else {
                include "./views/404.php";
            }
        }
    ?>
</body>
</html>

I tried verifying if there was a typo in the index.php file or some problem with the logic but I can't seem to see any issues.

本文标签: