PHP错误 - 标头睡眠功能不起作用

时间:2016-05-27 04:36:12

标签: php

我有一个PHP代码,其中包含headersleep 功能,可以在重定向页面时显示警报。但是sleep似乎没有起作用。

这是PHP代码,请检查:

<?php

   if ($query) { 
         echo '<script language="javascript">';
         echo 'alert("Registration SUCCESFUL")';
         echo '</script>';
         header('sleep(10);');
         header('Location: http://localhost/amberTAG%20requester/Login%20Page/Login.html');
 } else {
         echo '<script language="javascript">';
         echo 'alert("Registration UNSUCCESFUL, Sorry!")';
         echo '</script>';
    header('sleep(10);');
}
 ?>       

谢谢,

2 个答案:

答案 0 :(得分:3)

只需使用sleep而不使用header

sleep(10);
header('Location: http://localhost/amberTAG%20requester/Login%20Page/Login.html');

或使用:

header('refresh:10; URL=http://localhost/amberTAG%20requester/Login%20Page/Login.html');

答案 1 :(得分:1)

如果您想在提醒之前使用睡眠,则应使用setTimeout JavaScript

试试这个:

setTimeout(function(){
    alert("Registration UNSUCCESFUL, Sorry!");
}, 10000);

并且,如果您想在URL重定向之前使用sleep,请尝试:

header( "refresh:10;url=yoururl.html" );
相关问题