php 延时跳转

php header延时自动跳转:

大多情况下,我们都用这种header(“location:index.php”);

这种是直接跳转的,不会延时。

php也有一个延时函数,sleep();可是可以,但是不实用。

例如延时,是因为需要发送ajax时,sleep()就不适用,所以改为:

// put process in backend and send the file by mail
ob_end_clean();
header("Refresh:3;url=/delia/index.php");
header("Connection: close\r\n");
header("Content-Encoding: none\r\n");
ignore_user_abort(true);
ob_start();

// logout user
session_destroy();
echo Delia::$translate->_('The generation of your export has now started and will be sent to you by email.<br />The generation process can take several minutes before you receive it.<br />You have been logged out of the Mu back office and you will be redirected to the login page in 3 seconds.');

$size = ob_get_length();
header("Content-Length: $size");
while (@ob_end_flush());
flush();
ob_end_clean();
Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s