这是我的index.php文件,当用户未登录时会加载登录页面,否则会加载应用程序
$user = new User();
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="assets/css/master.css"/>
<script src="assets/js/functions.js?<? filectime('assets/js/functions.js') ?>"></script>
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
<script src="assets/vendor/jquery-validation/jquery.validate.min.js"></script>
<script src="assets/vendor/jquery-validation/additional-methods.min.js"></script>
<link rel="stylesheet" href="assets\vendor\bootstrap\dist\css\bootstrap.css">
</head>
<body>
<div class="main-wrapper container-fluid">
<?
if($user->isLoggedIn()) {
include_once 'app/index.php';
} else {
include_once 'files/auth/login.php';
}
?>
</div>
</body>
</html>
这是在用户未登录时加载的login.php文件
<div class="login-card">
<form id="sign-in-form">
<h2>Sign in</h2>
<div class="form-group">
<input type="text" name="username" required class="form-control" placeholder="Username">
<input type="password" name="password" required class="form-control" placeholder="Password">
<button type="submit" class="btn btn-primary btn-lg btn-block">sign in</button>
</div>
</form>
</div>
<div class="login-links">
<a href="" id="register-link">Create an account</a>
<a href="" class="grid-justify-end">Forgot password</a>
</div>
<script src="files/auth/js/login.js?<?= filemtime('files/auth/js/login.js') ?>"></script>
当用户单击创建帐户时,将调用Ajax函数,并在main-wrapper div中加载注册页面,但是当它加载到我的php类中时,用户是否感到困惑?并且index.php中的$ user变量也是未定义的
答案 0 :(得分:-1)
尝试在注册文件中包含包含用户类的文件。
答案 1 :(得分:-1)
赞这个
include 'path/to/users_phph_file/Users.php';
$user = new User();
如果您的文件夹结构如下所示:
根 类 --users.php index.php
然后
include 'classes/Users.php';
$user = new User();