php success error 封装跳转

/**
 * Warning提示信息
 * @param string $type 提示类型 默认支持success, error, info
 * @param string $msg 提示信息
 * @param string $url 跳转的URL地址
 * @param string $time 信息提示时间
 * @return void
 */
function alert($type='info', $msg='', $url='', $time=1000) {
    //多行URL地址支持
    $url        = str_replace(array("\n", "\r"), '', $url);
    $alert = unserialize(stripslashes(cookie('alert')));
    if (!empty($msg)) {
        $alert[$type][] = $msg;
        cookie('alert', serialize($alert));
    }
    cookie('alerttime', $time);
    
    if (empty($url)) {
        $url = U('index/index'); //定义无URL时的跳转地址
    }
    if (!headers_sent()) {
        header('Location: ' . $url);
        exit();
    } else {
        $str    = "<meta http-equiv='Refresh' content='0;URL={$url}'>";
        exit($str);
    }
    return $alert;
}

 

/**
 * Warning提示信息
 * @param string $type 提示类型 默认支持success, error, info
 * @param string $msg 提示信息
 * @param string $url 跳转的URL地址
 * @param string $time 信息提示时间
 * @return void
 */
function alert($type='info', $msg='', $url='', $time=1000) {
    //多行URL地址支持
    $url        = str_replace(array("\n""\r"), '', $url);
    $alert = unserialize(stripslashes(cookie('alert')));
    if (!empty($msg)) {
        $alert[$type][] = $msg;
        cookie('alert'serialize($alert));
    }
    cookie('alerttime', $time);
    
    if (empty($url)) {
        $url = U('index/index'); //定义无URL时的跳转地址
    }
    if (!headers_sent()) {
        header('Location: ' . $url);
        exit();
    } else {
        $str    = "<meta http-equiv='Refresh' content='0;URL={$url}'>";
        exit($str);
    }
    return $alert;
}
posted @ 2020-01-15 15:55  凡斗  阅读(374)  评论(0编辑  收藏  举报