页面跳转友好提示的php方法函数

用于当用户提交页面或某些操作完成 成功或者失败时的友好提示 以及跳转到相应地址的一个方法

如图所示的效果,还有错误的效果没截图 自己测试吧
2016-04-17_160107

    /**
     * http://www.zhangxingju.com 整理编辑
     * @param string $action  提示类型
     * @param string $content  提示内容
     * @param string $redirect  跳转链接
     * @param int $timeout  等待时间
     */
    public function message($action = 'success', $content = '', $redirect = 'javascript:history.back(-1);', $timeout = 5) {
		switch ($action) {
			case 'success' :
				$titler = '操作完成';
				$class = 'message_success';
				$images = 'message_success.png';
				break;
			case 'error' :
				$titler = '操作未完成';
				$class = 'message_error';
				$images = 'message_error.png';
				break;
			case 'errorBack' :
				$titler = '操作未完成';
				$class = 'message_error';
				$images = 'message_error.png';
				break;
			case 'redirect' :
				header ( "Location:$redirect" );
				break;
			case 'script' :
				if (empty ( $redirect )) {
					exit ( '<script language="javascript">alert("' . $content . '");window.history.back(-1)</script>' );
				} else {
					exit ( '<script language="javascript">alert("' . $content . '");window.location=" ' . $redirect . '   "</script>' );
				}
				break;
		}
		
		// 信息头部
		$header = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>操作提示</title>
<style type="text/css">
body{font:12px/1.7 "b8bf53",Tahoma;}
html,body,div,p,a,h3{margin:0;padding:0;}
.tips_wrap{ background:#F7FBFE;border:1px solid #DEEDF6;width:780px;padding:50px;margin:50px auto 0;}
.tips_inner{zoom:1;}
.tips_inner:after{visibility:hidden;display:block;font-size:0;content:" ";clear:both;height:0;}
.tips_inner .tips_img{width:80px;float:left;}
.tips_info{float:left;line-height:35px;width:650px}
.tips_info h3{font-weight:bold;color:#1A90C1;font-size:16px;}
.tips_info p{font-size:14px;color:#999;}
.tips_info p.message_error{font-weight:bold;color:#F00;font-size:16px; line-height:22px}
.tips_info p.message_success{font-weight:bold;color:#1a90c1;font-size:16px; line-height:22px}
.tips_info p.return{font-size:12px}
.tips_info .time{color:#f00; font-size:14px; font-weight:bold}
.tips_info p a{color:#1A90C1;text-decoration:none;}
</style>
</head>

<body>';
		// 信息底部
		$footer = '</body></html>';
		
		$body = '<script type="text/javascript">
        function delayURL(url) {
        var delay = document.getElementById("time").innerHTML;
        //alert(delay);
        if(delay > 0){
        delay--;
        document.getElementById("time").innerHTML = delay;
    } else {
    window.location.href = url;
    }
    setTimeout("delayURL(\'" + url + "\')", 1000);
    }
    </script><div class="tips_wrap">
    <div class="tips_inner">
        <div class="tips_img">
            <img src="' . Yii::app ()->baseUrl . 'www.zhangxingju.com/static/images/' . $images . '"/>
        </div>
        <div class="tips_info">

            <p class="' . $class . '">' . $content . '</p>
            <p class="return">系统自动跳转在  <span class="time" id="time">' . $timeout . ' </span>  秒后,如果不想等待,<a href="' . $redirect . '">点击这里跳转</a></p>
        </div>
    </div>
</div><script type="text/javascript">
    delayURL("' . $redirect . '");
    </script>';
		
		exit ( $header . $body . $footer );
	}