如何从php头触发一个模态弹出?



我正在尝试创建一个保护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">&times;</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>

模态窗口通过Javascript在客户端显示,例如如下所示。您需要用toast消息将用户发送回主页,告诉他们先登录。

你的重定向是不正确的,HTTP要求:后面有一个空格,像这样

header("Location: modallogin.php");

最新更新