+ -
当前位置:首页 → 问答吧 → PHP进行网页跳转

PHP进行网页跳转

时间:2009-08-25

来源:互联网

用PHP进行网页跳转,虽然可用header(),但还是觉得不够方便。

于是,自己写了个自定义函数redirect,很好用的。

[php]
function redirect($url,$str='',$url2=''){
if( $str=='' && $url2==''){
    echo "<script>location.href='".$url."'</script>";
    exit;
}
elseif( $str!='' && $url2==''){
         echo "<script>alert('".$str."');location.href='".$url."'</script>";
        exit;
}
elseif( $str!='' && $url2!=''){
     echo "<script>if(confirm('".$str."'))location.href='".$url."';else location.href='".$url2."';</script>";
    exit;
}
}
[/php]


只有1个参数(必须)-跳转网页 //如超出权限,删除记录后
有2个参数-跳转网页,提示 //如登录成功、添加成功
有3个参数-跳转网页,提示,另跳转网页 //如添加成功是否再次添加?


还有什么需要完善?请大家说说







作者: gdgzzmch   发布时间: 2009-08-25

看看~~~

作者: juanjuan   发布时间: 2009-08-26

还行吧

作者: fengrui   发布时间: 2009-08-27

不太懂

作者: 野鸭-小牛   发布时间: 2009-08-29

怎么混着script,不懂那个,得找时间学学!

作者: qk1987925   发布时间: 2009-08-30

a.php中
/*@param $url   必须,要跳转到目标页面的url
* @param $str   提示字符,在跳转到目标页面前,弹出的提示对话框上显现的字符
* @param $url2  要跳转的其他页面的url, 当弹出确认对话框, 按"取消"按钮后, 所要跳转的页面的url地址
* */
function redirect($url,$str='',$url2=''){
    if($str == '' && $url2 == ''){
        echo "<script>location.href='".$url."'</script>";
        exit;
    } elseif($str != '' && $url2 == ''){
        echo "<script>alert('".$str."');location.href='".$url."'</script>";
        exit;
    } elseif( $str != '' && $url2 != ''){
        echo "<script>if(confirm('".$str."'))location.href = '".$url."'; else location.href = '".$url2."';</script>";
        exit;
    }//end.if
}
//实验访问a.php跳转到b.php
redirect('http://localhost/demo/b);
//实验访问a.php,弹出提示对话框,上面显示x-man,按确定后页面跳转到b.php
redirect('http://localhost/demo/b.php',"X-man);
////实验访问a.php,弹出提示对话框,上面显示x-man,按取消后页面跳转到c.php
redirect('http://localhost/demo/b.php',"X-man",'http://localhost/demo/c.php');
?>

作者: lesliee   发布时间: 2009-08-31

有点不明白...

作者: valitiel   发布时间: 2009-09-14

了解一下!

作者: 闭门思过   发布时间: 2009-09-22

不错,收藏

作者: zhuxian225   发布时间: 2009-09-22

热门下载

更多