【发布时间】:2023-01-12 01:25:36
【问题描述】:
我正在尝试创建一个保护 php 页面,访问者必须在访问页面之前登录。系统将提示访问者使用模态表单登录。我可以知道如何实现这一目标吗?
这是通向 community.php 的锚点,需要在访问前登录:
<a href="community.php" class="communityText" style="cursor: pointer;">Share your ideas with our community!</a>
这是 community.php(我还没有构建很多页面):
<?php include "protection.php" ?>
<?php include "webhead.php" ?>
这是我的保护 php 页面:
<?php
session_start();
if($_SESSION['login_status'] != "ok") {
header("location:modallogin.php");
}
?>
这是我的模式 html:
<div id="loginModal" class="modal fade">
<div class="modal-dialog modal-login">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Please Login</h4>
<p></p>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<div class="modal-body">
<form action="checklogin.php" method="post">
<div class="form-group">
<label for="loginModalName">Username</label>
<input type="text" class="form-control" name="name" id="loginModalName" placeholder="Please enter your username" required="required">
<p></p>
<label for="loginModalPassword">Password</label>
<input type="password" class="form-control" name="password" id="loginModalPassword" placeholder="Please enter your password" required="required">
</div>
<div class="form-group">
<button type="submit" class="btn btn-lg btn-block login-btn" style="background-color: #fdbf50 !important; color: #f4f4f8 !important;">Login</button>
</div>
</form>
</div>
<div class="modal-footer"><a href="#">Join us now!</a></div>
</div>
</div>
</div>
</div>
【问题讨论】:
-
您不使用标头调用来处理此问题。
-
@ceejayoz 那我应该怎么处理?
-
JavaScript + AJAX 调用,或非模态方法。
标签: php html forms bootstrap-modal