Javascript 如何在php中添加延迟
用户单击验证链接时的帐户验证过程。他/她立即重定向到仪表板。但我想给他/她的帐户已经验证了几秒钟的确认信息。 这是我的密码Javascript 如何在php中添加延迟,javascript,php,Javascript,Php,用户单击验证链接时的帐户验证过程。他/她立即重定向到仪表板。但我想给他/她的帐户已经验证了几秒钟的确认信息。 这是我的密码 <?PHP require_once 'include/Functions.php'; $db = new DB_Functions(); if(isset($_GET['username'])&&isset($_GET['q'])) { $username= $_GET['username'];
<?PHP
require_once 'include/Functions.php';
$db = new DB_Functions();
if(isset($_GET['username'])&&isset($_GET['q']))
{
$username= $_GET['username'];
$hash= $_GET['q'];
$salt = "498#2D83B631%3800EBD!801600D*7E3CC13";
$resetkey = hash('sha512', $salt.$username);
if($hash==$resetkey){
$user = $db->activateAccount($username);
if ($user != false) {
// user is found
echo '<script>';
echo 'document.getElementById("result_status").innerHTML = "<strong>Congratulations! Your Account has been verified .</strong>"';
echo '</script>';
$passwords=$db->getPasswordFromUsername($username);
$users = $db->loginUserWithMdfPassword($username, $passwords);
if ($users != false) {
// password is found
$properlyLogged=true;
if($properlyLogged) {
// season for storing data start here
session_start();
$_SESSION['username']=$username;
header('Location: http://localhost/mywebsite/dashboard.php');
exit();
// season for storing data end here
}}
}
}else {
echo '<script>';
echo 'document.getElementById("result_status").innerHTML = "<strong>Session has been expired.</strong>"';
echo '</script>';
}}
?>
使用JavaScript方法可能会更容易
而不是标题('位置:http://localhost/mywebsite/dashboard.php');代码>
放
echo'设置超时(函数(){window.location.href=”http://localhost/mywebsite/dashboard.php"}, 5 * 1000);'代码>
这将等待X*1000毫秒(在我的示例中为5秒),然后重定向到目标。sleep
无法满足您的需要。
您正在使用标题('location:…')重定向您的用户代码>并且在输出数据后不能修改标题信息(即,向用户显示消息)。
您必须使用带有setTimeout
<?PHP
require_once 'include/Functions.php';
$db = new DB_Functions();
if(isset($_GET['username'])&&isset($_GET['q']))
{
$username= $_GET['username'];
$hash= $_GET['q'];
$salt = "498#2D83B631%3800EBD!801600D*7E3CC13";
$resetkey = hash('sha512', $salt.$username);
if($hash==$resetkey){
$user = $db->activateAccount($username);
if ($user != false) {
// user is found
echo '<script>';
echo 'document.getElementById("result_status").innerHTML = "<strong>Congratulations! Your Account has been verified .</strong>";';
// set timeout for 3 seconds - then redirect
echo "setTimout(function(){window.location.href = 'http://localhost/mywebsite/dashboard.php';},3000)"
echo '</script>';
$passwords=$db->getPasswordFromUsername($username);
$users = $db->loginUserWithMdfPassword($username, $passwords);
if ($users != false) {
// password is found
$properlyLogged=true;
if($properlyLogged) {
// season for storing data start here
session_start();
$_SESSION['username']=$username;
//comment out header redirect
//header('Location: http://localhost/mywebsite/dashboard.php');
exit();
// season for storing data end here
}}
使用Sleep函数:如何在代码中使用它?你能告诉我吗?