作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
添加标题(位置:homepage.php)
后,我的模式没有显示,但如果删除标题
,模式就可以正常工作。我怎么可能做到呢?我也尝试过使用 echo 进行警报,并且发生了同样的事情,所以我不知道我的代码出了什么问题。我希望有人能帮助我谢谢!这是我的代码
登录.php
if(isset($_POST['submit']))
{
$email = $_POST['email'];
$password = $_POST['password'];
$object = new Login();
$object->getCredentials($email, $password);
}
?>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="POST">
<div>
<label><b>EMAIL ADDRESS</b></label>
<input type="email" name="email" placeholder="Email"></input>
</div>
<div>
<label><b>PASSWORD</b></label>
<input type="password" name="password" placeholder="Password"></input>
</div>
<button type="submit" id="submit" name="submit">Login</button>
</form>
进程登录.php
<?php
include_once 'db.php';
class Login
{
public function getCredentials($email, $password)
{
$email = $email;
$password = $password;
$object = new Db();
$stmt = $object->connect()->prepare("SELECT * FROM user WHERE email=?");
$stmt->execute([$email]);
$stmtFetch = $stmt->fetch();
if($stmt->rowCount()==1 && $stmtFetch['email'] == $email && $stmtFetch['password'] == $password)
{
echo "<script>$('#loginsuccess').modal('show')</script>";
header("location: homepage.php");
}
}
}
最佳答案
我在这里发现了您可能感兴趣的东西:
Interview Question: Can we have an echo before header?
问题是我们开始发送输出后无法发送 header ,如果在 echo
之前发送 header ,echo
将不会被执行。
试试这个:
解决方案 1:(来自上面的链接)。
ob_start();
echo "<script>$('#loginsuccess').modal('show')</script>";
header("location: homepage.php");
ob_end_flush();
解决方案 2:使用 JavaScript 重定向而不是 header 函数。
echo "<script>
$('#loginsuccess').modal('show');
window.location.replace('http://fullpath-homepage.php');
</script>";
附加说明:
您还可以使用:
window.location.href="http://example.com";
window.location.assign("http://example.com");
replace
方法导航到 URL,而不向历史记录添加新记录。
关于javascript - 在php中登录后不显示模态框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50420695/
我来自 Asp.Net 世界,试图理解 Angular State 的含义。 什么是 Angular 状态?它类似于Asp.Net中的ascx组件吗?是子页面吗?它类似于工作流程状态吗? 我听到很多人
我一直在寻找 3 态拨动开关,但运气不佳。 基本上我需要一个具有以下状态的开关: |开 |不适用 |关 | slider 默认从中间开始,一旦用户向左或向右滑动,就无法回到N/A(未回答)状态。 有人
我是一名优秀的程序员,十分优秀!