Problem with refresh

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • susee
    New Member
    • Mar 2008
    • 10

    Problem with refresh

    header("refresh : 5; $url");
    i used the above code to refresh the contents of a page every 5 seconds.
    but i got the following errosr
    Warning: Cannot modify header information - headers already sent by (output started at c:\rss\magpie_s imple_2.php:3) in c:\rss\magpie_s imple_2.php on line 86

    so i added these two lines
    header("Cache-Control: no-cache, must-revalidate");
    header("Expires : Mon, 26 Jul 1997 05:00:00 GMT");

    even after that am getting the same warning for the above code.

    pls help.its important
  • satas
    New Member
    • Nov 2007
    • 82

    #2
    You should send headers before any other information to output.
    Make sure your script has no output before sending headers. It could be spaces, html-tags even php-errors.

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      On line 3 of magpie_simple_2 .php you have output something to the browser.
      Post your code and we'll have a look see :)

      Comment

      • susee
        New Member
        • Mar 2008
        • 10

        #4
        Originally posted by markusn00b
        On line 3 of magpie_simple_2 .php you have output something to the browser.
        Post your code and we'll have a look see :)
        Actually I have a widget inside which Im displaying the o/p from the php script which worked good for static case and giving this error when I tried to make it dynmic by refreshing.On line 3 I ve defined the style of the widget.

        code snippets:
        <html>
        <head>
        <style>--- line no : 3
        .widget{
        width: 300;
        min-height: 50px;
        border: 1px solid #CACACA;
        background-color: #FFFFFF;
        }
        .....
        .....
        ....
        <body>
        <div id='widget1' class='widget'. ....
        ......
        ......
        <?php
        if($_GET['var'])
        {
        $var = $_REQUEST['var'];
        }
        $url = "http://rss/magpierss/$var.xml";
        define('MAGPIE_ DIR', 'c:\\rss\\magpi erss\\');
        require_once(MA GPIE_DIR.'rss_f etch.inc');
        header("Cache-Control: no-cache, must-revalidate");
        header("Expires : Mon, 26 Jul 1997 05:00:00 GMT");
        header("refresh : 5; $url");
        ...
        ....
        .....
        ?>
        </div>
        </body>
        </html>


        Need help ASAP

        Comment

        • satas
          New Member
          • Nov 2007
          • 82

          #5
          susee, headers can not be sent after any HTML code. Do you understand it?

          Comment

          • susee
            New Member
            • Mar 2008
            • 10

            #6
            Originally posted by satas
            susee, headers can not be sent after any HTML code. Do you understand it?
            oh thank u....
            then how can i refresh the content is there any other way of doing it apart from hearder()?

            Comment

            • satas
              New Member
              • Nov 2007
              • 82

              #7
              Try this
              [PHP]<?php
              if($_GET['var'])
              {
              $var = $_REQUEST['var'];
              }
              $url = "http://rss/magpierss/$var.xml";
              define('MAGPIE_ DIR', 'c:\\rss\\magpi erss\\');

              //hope this file has no output in the bowser
              require_once(MA GPIE_DIR.'rss_f etch.inc');
              header("Cache-Control: no-cache, must-revalidate");
              header("Expires : Mon, 26 Jul 1997 05:00:00 GMT");
              header("refresh : 5; $url");
              ...
              ?>
              <html>
              <!- html code here-->

              <?php
              // php code here
              .....
              ?>
              <!- html code here-->
              </html>
              [/PHP]

              Comment

              • Ravigandha
                New Member
                • Mar 2008
                • 17

                #8
                Originally posted by susee
                header("refresh : 5; $url");
                i used the above code to refresh the contents of a page every 5 seconds.
                but i got the following errosr
                Warning: Cannot modify header information - headers already sent by (output started at c:\rss\magpie_s imple_2.php:3) in c:\rss\magpie_s imple_2.php on line 86

                so i added these two lines
                header("Cache-Control: no-cache, must-revalidate");
                header("Expires : Mon, 26 Jul 1997 05:00:00 GMT");

                even after that am getting the same warning for the above code.

                pls help.its important
                hello, just put this code
                [PHP] error_reporting (0);[/PHP]
                on the first line and give a shot.hope it will be solved?

                Comment

                • Markus
                  Recognized Expert Expert
                  • Jun 2007
                  • 6092

                  #9
                  Hello, susee and welcome to TSDN!

                  As has been mentioned before (possibly in a somewhat harsh tone - satas) headers are required to be sent before anything is output to the browser. It's simple to abide by once you understand.

                  Anyway, is it paramount that the php be refreshed or do you just want the html/css/javascript/widget to be refreshed?

                  If the last one is the case, have a look at META tags. There's a useful one that refreshes the page on any given amount of time!

                  [html]
                  <META
                  HTTP-EQUIV="refresh"
                  content="2;
                  URL=http://www.yoursite.co m/newpage.htm">
                  [/html]
                  Content: Timer for refreshing.
                  URL: This is self explanatory :P

                  Hope this helps!

                  Comment

                  • susee
                    New Member
                    • Mar 2008
                    • 10

                    #10
                    Originally posted by markusn00b
                    Hello, susee and welcome to TSDN!

                    As has been mentioned before (possibly in a somewhat harsh tone - satas) headers are required to be sent before anything is output to the browser. It's simple to abide by once you understand.

                    Anyway, is it paramount that the php be refreshed or do you just want the html/css/javascript/widget to be refreshed?

                    If the last one is the case, have a look at META tags. There's a useful one that refreshes the page on any given amount of time!

                    [html]
                    <META
                    HTTP-EQUIV="refresh"
                    content="2;
                    URL=http://www.yoursite.co m/newpage.htm">
                    [/html]
                    Content: Timer for refreshing.
                    URL: This is self explanatory :P

                    Hope this helps!
                    Thanks for your reply markusn00b but as I din turn back to office for few days I could not continue..you have caught my exact issue... I need to erfresh my php part not jus the page.I have to call the fetch rss () every 5 seconds.

                    Thanks in advance...
                    Susee

                    Comment

                    • susee
                      New Member
                      • Mar 2008
                      • 10

                      #11
                      Is there any other way to refresh? I mean other than this header refresh which may help refresh my php part alone?

                      Comment

                      • Markus
                        Recognized Expert Expert
                        • Jun 2007
                        • 6092

                        #12
                        Hey susee! Sorry for the late reply!

                        You can still use the header refresh without problems (and if you want to refresh the page server-side you HAVE to do it with the header refresh).

                        You should take a look at satas' post (#7) just up there ^

                        If you need anymore help, let us know.

                        Regards, markus.

                        Comment

                        • susee
                          New Member
                          • Mar 2008
                          • 10

                          #13
                          Originally posted by markusn00b
                          Hey susee! Sorry for the late reply!

                          You can still use the header refresh without problems (and if you want to refresh the page server-side you HAVE to do it with the header refresh).

                          You should take a look at satas' post (#7) just up there ^

                          If you need anymore help, let us know.

                          Regards, markus.
                          I ve tried satas' idea already, but if i do so my page will display the content in an unpreffered manner. I want to display the HTML widget inside which I have to display the output form the PHP part.Help me out to do this.

                          Comment

                          Working...