2013-07-02 10:18



I am trying to write a page in php which shows a loading message while it does some processing and then auto redirects to another page

    //show a loading message - this is the bit I need help with
    // do some processing - don't need help with this bit

I can't use echo or javascript otherwise I get a "Cannot modify header information - headers already sent" error when the page executes.

Any clues?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • dongzhun1857 dongzhun1857 8年前

    Using java script to redirect after the processing has finished seems to be the way to go.

    I'm using

    <script type="text/javascript">

    at the end of the page and it's working

    点赞 评论 复制链接分享
  • dongzai0020 dongzai0020 8年前

    First of all, you mustn't use any header change after outputing some data, that is why you get the error above. Another way, use header redirections by refreshing page on next page:

        header('Refresh: 5; url=' ); 
        echo 'Wait 5 sec then redirected';


    Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

    点赞 评论 复制链接分享
  • dpbyr64224 dpbyr64224 8年前

    Best way is to use ajax requests. Via javascript you should show the loading element, perform the request, on success redirect on target page

    点赞 评论 复制链接分享