一些下载网站提示,xx秒后开始下载文件,这个实现的实质是在http响应头中添加Refresh并制定秒数和转向的新地址,代码如下。

<?php
// if name via get equals 'download", show the downloading message.
if($_GET['name'] == "download"){
echo "Downloading ... ";
}else{
// set refresh to 3 seconds, make the variable name be 'download' via the get method;
header("Refresh: 3: url=http://youkud.com/index.php?name=download");
// show this message
echo "You can download in 3 seconds.";
}