为了账号安全,请及时绑定邮箱和手机立即绑定

多个标头/

多个标头/

PHP
慕哥9229398 2022-09-25 20:45:58
我使用标题在提交后显示成功消息。我还想在5秒后将用户重定向到索引.php页面,但不知何故它不起作用。if(mysqli_query($link, $sql)){    header("Location: addbusiness.php?message=<div class='alert alert-success' role='alert' style='text-align: center; margin-bottom: 50px;'>Succes.</div>");    header( "refresh:5;url=index.php" );} else{    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);}
查看完整描述

1 回答

?
慕斯王

TA贡献1864条经验 获得超2个赞

您根本无法同时执行,因此您必须将两个标题分开,即应该是显示消息的页面的一部分。此外,没有理由(实际上是一种不好的做法)将整个HTML传递到URL中,最好使用一些ID,例如:locationrefreshrefresh


数据库.php


<?php

    if(mysqli_query($link, $sql)){

        header("Location: addbusiness.php?message=1");

    } else{

        echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);

    }

?>

附加业务.php


<?php

    if(!empty($_GET['message'])){

        if($_GET['message'] == 1){

            header( "refresh:5;url=index.php" );

            echo "<div class='alert alert-success' role='alert' style='text-align: center; margin-bottom: 50px;'>Success.</div>";

        }else{

            //do something else

        }

    }

?>

基于这样的条件,您还将避免每次访问时刷新addbusiness.php


当然,在任何情况下,您都必须确保在调用之前没有任何HTML输出到浏览器。在两个页面中。header()


查看完整回答
反对 回复 2022-09-25
  • 1 回答
  • 0 关注
  • 111 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号