PHP实现弹出提示框后返回上一个页面
<?php
echo "<script>alert('退出成功!');location.href='".$_SERVER["HTTP_REFERER"]."';</script>";
?>
alert里面是提示的消息,href是提示后跳转的页面。
如果alert中文乱码,加入下面代码
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
我们可以考虑封装成函数来调用,下面是我自己封装的页面跳转函数
/**
* 页面跳转方法
* @param $msg 提示说明
* @param null $path 跳转路径
* @param null $parent 为ture则返回父窗口
*/
function messageInfo($msg,$path=NULL,$parent=NULL){
if($parent === true){
$str="<script>alert('".$msg."');parent.location.href='".$path."‘</script>";
}else if(empty($path)){
$str="<script>alert('".$msg."');history.back()</script>";
}else{
$str="<script>alert('".$msg."');location.href='".$path."'</script>";
}
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';//支持中文
echo $str;
}
使用方法:messageInfo(‘操作成功!’,’http://www.demourl.com/product_list.php’);
其他跳转方法
代码如下:
echo "<script> alert('no loginid'); </script>";
echo "<meta http-equiv='Refresh' content=0; URL=$url>";
$url就是要跳转的页面,同时,这个还能控制跳转时间,content后面的0就是表示0秒后跳转。
两个直接跳转的方式:
代码如下:
header("Location:".PSYS_BASE_URL."user/index");
代码如下:
// echo "<script> alert('创建tag成功!'); </script>";
// header("refresh:3;url='createTag' ");
以上内容希望帮助到大家,很多PHPer在进阶的时候总会遇到一些问题和瓶颈,业务代码写多了没有方向感,不知道该从那里入手去提升,对此我整理了一些资料,包括但不限于:分布式架构、高可扩展、高性能、高并发、服务器性能调优、TP6,laravel,YII2,Redis,Swoole、Swoft、Kafka、Mysql优化、shell脚本、Docker、微服务、Nginx等多个知识点高级进阶干货需要的可以免费分享给大家,需要
PHP进阶架构师>>>视频、面试文档免费获取shimo.im![48d4a94d22160d421255788218d65807.png](https://img-blog.csdnimg.cn/img_convert/48d4a94d22160d421255788218d65807.png)
或 者关注咱们下面的知乎专栏
PHP大神进阶zhuanlan.zhihu.com![9cef59a8fd0ba0e2affd0c457ef4b9de.png](https://img-blog.csdnimg.cn/img_convert/9cef59a8fd0ba0e2affd0c457ef4b9de.png)