YRedirect.class.php
987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
/**
* 封装页面跳转方法
*
* @version 0.1 2012-6-25
* @name Framework_Response_YForward
* @author xiaoma
*/
class Framework_Response_YRedirect
{
/**
* 重定向 URL
*
* @var string
*/
protected $url;
/**
* 重定向延时(秒)
*
* @var int
*/
protected $delay;
/**
* 脚本(当delay>0时有效)
*
* @var string
*/
protected $scripts;
/**
* 构造函数
*
* @param string $url
* @param int $delay
*/
public function __construct($url, $delay = 0, $scripts = '')
{
$this->url = $url;
$this->delay = $delay;
$this->scripts = $scripts;
}
/**
* 执行
*/
function execute()
{
$url = $this->url;
$delay = (int) $this->delay;
if ($delay > 0)
{
$scripts = $this->scripts;
return <<<EOT
<html>
<head>
<meta http-equiv="refresh" content="$delay;URL=$url" />
<script type="text/javascript>$scripts</script>
</head>
</html>
EOT;
}
else
{
header('Location: ' . $url);
}
}
}