donglulong0877 2015-03-13 13:32
浏览 71
已采纳

有没有办法在不使用header()的情况下重定向到php中的另一个页面?

Is there a way to redirect to another page in php without using header()? I can't use header() because I am outputting some stuff first to the page. I've considered using Javascript's window.location but I'm using an if statement in php so is there any way in php to go to another page without using header()? Thanks in advance.

  • 写回答

2条回答 默认 最新

  • dongzhang3482 2015-03-13 14:02
    关注

    I can't use header() because I am outputting some stuff first to the page.

    You shouldn't dismiss using header(). Using header() is still achievable by using output buffering.

    For example:

    <?php
    
    ob_start(); //start the buffer
    echo "This is some output"; //Output data
    ob_clean(); //Erase the buffer content
    header('Location: http://google.com'); //Redirect user
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?