2016-10-03 69 views
1

中添加帳戶驗證過程中的延遲。他/她立即重定向到儀表板。但是我想給出一個確認消息,說明他/她的賬戶已經過了幾秒鐘的驗證。 這裏是我的代碼當用戶點擊驗證鏈接時,如何在php

    <?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>'; 




}} 



?> 
+1

瓶坯重定向可以使用睡眠功能:http://php.net/manual/en/function.sleep.php –

+0

我如何使用它在我的代碼?你能告訴我嗎? –

回答

0

這可能會更容易與JavaScript的方法。

代替header('Location: http://localhost/mywebsite/dashboard.php');

echo '<script>setTimeout(function(){window.location.href = "http://localhost/mywebsite/dashboard.php"}, 5 * 1000);</script>'

這將等待X * 1000毫秒(在我的例子,5秒),然後重定向到目的地。

+0

非常有幫助謝謝 –

1

sleep不會爲你想要的工作。 您正在使用header('location:...');重定向您的用戶,並且您在輸出數據(即 - 向用戶顯示消息)後無法修改標題信息。 你必須使用JavaScript與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 
}} 
+0

非常感謝它的作品。 –

相關問題