Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从包含中更改包含_Php - Fatal编程技术网

Php 从包含中更改包含

Php 从包含中更改包含,php,Php,我有一个仪表板,它使用includes使其成为一个带有可变includes的静态页面。它使用GET从URL获取请求的页面 在这个include中,我有一个登录页面,当用户登录时,我希望它重定向到帐户页面。然后我不得不影响包含之外的页面,但由于某些原因它不起作用 在本例中,我使用了$会话变量,如果它被登录,它将包含account页面,但它不起作用。我是否使用了错误的方法来实现我的目标 dashboard.php <?php session_start(); if($_SESSION['isL

我有一个仪表板,它使用includes使其成为一个带有可变includes的静态页面。它使用GET从URL获取请求的页面

在这个include中,我有一个登录页面,当用户登录时,我希望它重定向到帐户页面。然后我不得不影响包含之外的页面,但由于某些原因它不起作用

在本例中,我使用了$会话变量,如果它被登录,它将包含account页面,但它不起作用。我是否使用了错误的方法来实现我的目标

dashboard.php

<?php
session_start();
if($_SESSION['isLoggedIn'] = TRUE){
    $page = "dashboard-parts/account";
};
?>
<html>
<head>
<title>Dashboard</title>
<link rel="stylesheet" type="text/css" href="css/dashboard-style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js">  
</script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css?family=Nunito+Sans:300,400,600,700" rel="stylesheet">
<link rel="stylesheet" href="fonts/font-awesome/css/font-awesome.min.css">
</head>

<body>
<div id="wrapper">
    <div id="top-bar">
        <h1 id="logo">Logo</h1>

        <ul>
            <li class="social-link"><a href=""><i class="fa fa-linkedin" aria-hidden="true" ></i></a></li>
            <li class="social-link"><a href=""><i class="fa fa-instagram" aria-hidden="true"></i></a></li>
            <li class="social-link"><a href=""><i class="fa fa-pinterest" aria-hidden="true"></i></a></li>
            <li class="social-link"><a href=""><i class="fa fa-twitter" aria-hidden="true"></i></a></li>
            <li class="social-link"><a href=""><i class="fa fa-facebook-official" aria-hidden="true"></i></a></li>
        </ul>
    </div>

    <div id="nav">
        <ul>
            <li><a href="dashboard.php?page=dashboard-parts/account" class="nav-item">Account</a></li>
            <li><a href="dashboard.php?page=dashboard-parts/statistics" class="nav-item">Statistics</a></li>
            <li><a href="dashboard.php?page=dashboard-parts/tasks" class="nav-item">Tasks</a></li>
            <li><a href="dashboard.php?page=dashboard-parts/research" class="nav-item">Research</a></li>
            <li><a href="dashboard.php?page=dashboard-parts/inbox" class="nav-item">Inbox</a></li>
            <li><a href="dashboard.php?page=dashboard-parts/support" class="nav-item">Support</a></li>
            <li><a href="dashboard.php?page=dashboard-parts/upgrade" id="upgrade" class="nav-item">Upgrade</a></li>
        </ul>
    </div>

    <div id="content">
        <?php
            $page = $_GET['page'];
            $pages = array('dashboard-parts/account',
                            'dashboard-parts/statistics',
                            'dashboard-parts/tasks',
                            'dashboard-parts/research',
                            'dashboard-parts/inbox',
                            'dashboard-parts/support',
                            'dashboard-parts/login',
                            'dashboard-parts/reg',
                            'dashboard-parts/upgrade');
            if (!empty($page)) {
                if(in_array($page,$pages)) {
                    $page .= '.php';
                    include($page);
                }
                else {
                echo 'Page not found. Return to the
                <a href="dashboard-parts/login.php">login page.</a>';
                }
            }
            else {
                include('dashboard-parts/login.php');
            }
        ?>
    </div>
</div>

</body>
</html>

仪表板
标志
Login.php:

<html>
<head>
<title>Dashboard</title>
<link rel="stylesheet" type="text/css" href="css/login-style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://fonts.googleapis.com/css?family=Nunito+Sans:300,400,600,700" rel="stylesheet">
<link rel="stylesheet" href="fonts/font-awesome/css/font-awesome.min.css">
</head>

<body>
<div class="wrapper">
    <div id="login-box">
        <form method="post" action="">
            <div>
                <input placeholder="Username" type="text" name="username" id="username">
            </div>
            <div>
                <input placeholder="Password" type="password" name="password" id="password">
            </div>
            <input class="submit" type="submit" name="login_submit" value="Log In">
        </form>
        <a href="dashboard.php?page=dashboard-parts/reg">Don't have an account? Click here!</a>
    </div>
</div>
</body>
</html>


<?php
include_once ('dbstuff.inc');
session_start();
echo $_SESSION['isLoggedIn'];

if(isset($_POST['login_submit'])){

$errors = array();

//Basic validation
if(empty($_POST['username'])){
    $errors[] = "Please enter your username";
}else{
    $username = $conn->real_escape_string($_POST['username']);
}

if(empty($_POST['password'])){
    $errors[] = "Please enter your password";
}else{
    $password = trim($_POST['password']);
}

if (empty($errors)) {
    $sql = "SELECT * FROM users WHERE username = '$username'";
    $result = $conn->query($sql);
    if ($result->num_rows === 1) {
        $row = $result->fetch_array(MYSQLI_ASSOC);
        if (password_verify($password, $row['password'])) {
            //Password matches, so create the session and send to dashboard
            $_SESSION['user']['user_id'] = $row['user_id'];
            $_SESSION['isLoggedIn'] = True;
            //Sets the user to logged in
            echo $_SESSION['isLoggedIn'];
            exit;
        }else{
            $errors[] = "The username or password do not match";
        }
    }else{
        $errors[] = "The username or password do not match";
    }
}
}

?>

仪表板

似乎当您第一次设置
$page=“dashboard parts/account”,它没有任何区别,因为您稍后再次设置它
$page=$\u GET['page']

首先,您并没有检查用户是否已登录,而是在让他登录

 if($_SESSION['isLoggedIn'] = TRUE){
    $page = "dashboard-parts/account";
}
您有
=
(赋值)而不是
==
(比较)