我正在用 PHP 创建一个登录系统,并试图让它变得更好一点。
当您注销时,您会被重定向回index.php。像这样:
header("loaction: index.php?logout=true")
这使得 url 看起来像 www.mysite.com/index.php?logout=true。然后我使用以下代码:
if(isset($_GET['logout'])) {
$logoutvalue = $_GET['logout'];
if($logoutvalue = "true") {
$notification = "You've been logged out!";
}
从 URL 获取注销值并对其执行某些操作。
我有一个小的弹出窗口,将显示通知变量的值。在本例中,它是“您已注销!”我的问题是如何在页面加载时以及 url 等于 /index.php?logout=true 时显示模式窗口?
非常感谢所有意见、答案和建议!
谢谢!
- 瑞安
首先,
您不能直接“使用 PHP 打开模态窗口”。
您只能通过交换变量(通过 JSON 或 XML)或将 PHP 条件直接嵌入到标记中来实现此目的。
PHP 和 JavaScript 是独立的。
我的问题是如何让模式窗口在页面显示时显示
加载并且当 url 等于 /index.php?logout=true 时?
有两种方法可以实现这一目标。
First:充分利用将 PHP 条件直接嵌入到标记中。
Second:在某处隐藏输入,例如(<input type="hidden" id="showModal" />
),然后通过 JavaScript 本身检查它是否存在。
例如:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
window.onload = function(){
if ( document.getElementById('showModal') ){
alert('Box'); //replace with your own handler
}
}
</script>
</head>
<body>
<?php if ( isset($_GET['logout']) && $_GET['logout'] === 'true' ): ?>
<input type="hidden" id="showModal" />
<?php endif;?>
</body>
</html>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)