2016-10-03 7 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');

는 X * 1000 (내 예에서는 5 초) 밀리와의 목적지로 리디렉션 대기

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

을 넣어.

+0

매우 도움이 감사합니다 –

1

sleep 원하는대로 작동하지 않습니다. header('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 
}} 
+0

덕분에 많은 작품. –

관련 문제