如何从php头中触发模态弹出窗口?

d5vmydt9  于 2023-01-12  发布在  PHP
关注(0)|答案(1)|浏览(134)

我正在尝试创建一个保护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>
xzlaal3s

xzlaal3s1#

模态窗口是通过Javascript在客户端显示的,例如,您需要让用户返回主页,并发送一条吐司消息,告诉他们先登录。
您的重定向不正确,HTTP要求在:后留一个空格,如下所示

header("Location: modallogin.php");

相关问题