首页 > 解决方案 > PHP打开链接然后执行函数

问题描述

我最近开始使用 php 和 mysql 数据库构建登录系统。现在我已经使用 php 代码和用户在引导模式中键入的数据构建了它。

用户打开他的邮箱,单击在数据库中执行验证脚本的链接以将用户设置为已验证并加载我的主站点页面。

之后,我想添加一些模式来告诉类似“您的帐户已验证”之类的内容。什么是正确的方法?我认为它可以通过运行位于index.php类似的 jquery 函数由 php 完成

<?php
    header('location:index.php');
    echo "<script> $('#addText').modal();</script>";
?>

但正如我所见,这是不正确index.php的,php 只是加载,仅此而已。

PS我很抱歉我对php基础知识的无知。

标签: javascriptphpjquery

解决方案


如果您使用 HTTP 重定向,页面的内容将被忽略。

相反,您可以使用允许延迟重定向的元刷新标记。

<head>
<meta http-equiv="refresh" content="5;url=https://example.com/index.php" />
<script src="js/jquery.js">
<script> $(function() {$('#addText').modal();})</script>
</head>

5;表示延迟刷新5秒。


推荐阅读