Reload (refresh) page within an if statement

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • T. Wintershoven

    Reload (refresh) page within an if statement

    Hi all,

    Is there a simple way in php to reload a page coded within an if
    statement.(see code below)
    It's very important that the session stays intact.
    The filename is RCStudent.php

    *************** * A peace of code*********** *************** *
    <?php
    session_start() ;
    ?>

    if($_POST['ST']!='')
    {
    $_SESSION['nScreen']=2'';
    }
    elseif ($_POST['AT']!='')
    {
    $_SESSION['nScreen']=0'';

    *** RELOAD CODE HERE ***
    }

    *************** **** End code*********** *************** *****

    T.i.a.

    Regards,

    Tino Wintershoven.
    The Netherlands.


  • Shelly

    #2
    Re: Reload (refresh) page within an if statement

    "T. Wintershoven" <twintershoven@ casema.nlwrote in message
    news:raqdnVvfto LyvfHYnZ2dnUVZ8 tSdnZ2d@casema. nl...
    Hi all,
    >
    Is there a simple way in php to reload a page coded within an if
    statement.(see code below)
    It's very important that the session stays intact.
    The filename is RCStudent.php
    >
    *************** * A peace of code*********** *************** *
    <?php
    session_start() ;
    ?>
    >
    if($_POST['ST']!='')
    {
    $_SESSION['nScreen']=2'';
    }
    elseif ($_POST['AT']!='')
    {
    $_SESSION['nScreen']=0'';
    >
    *** RELOAD CODE HERE ***
    }
    >
    *************** **** End code*********** *************** *****
    Do a header("Locatio n: this_page_with_ appropiate_para meter_passing") ; ?

    Shelly


    Comment

    • T. Wintershoven

      #3
      Re: Reload (refresh) page within an if statement

      Hi Shelly,

      Thanks for your reaction.

      When i do a header(location ), i get an error message:
      Warning: Cannot modify header information - headers already sent.

      The header is allready sent on the second line ... session_start() ... (see
      code)

      Tino



      "Shelly" <sheldonlg.news @asap-consult.comwrot e in message
      news:9AVah.4038 $sf5.623@newsre ad4.news.pas.ea rthlink.net...
      "T. Wintershoven" <twintershoven@ casema.nlwrote in message
      news:raqdnVvfto LyvfHYnZ2dnUVZ8 tSdnZ2d@casema. nl...
      Hi all,

      Is there a simple way in php to reload a page coded within an if
      statement.(see code below)
      It's very important that the session stays intact.
      The filename is RCStudent.php

      *************** * A peace of code*********** *************** *
      <?php
      session_start() ;
      ?>

      if($_POST['ST']!='')
      {
      $_SESSION['nScreen']=2'';
      }
      elseif ($_POST['AT']!='')
      {
      $_SESSION['nScreen']=0'';

      *** RELOAD CODE HERE ***
      }

      *************** **** End code*********** *************** *****
      >
      Do a header("Locatio n: this_page_with_ appropiate_para meter_passing") ; ?
      >
      Shelly
      >
      >

      Comment

      • Ric

        #4
        Re: Reload (refresh) page within an if statement

        Not sure exactly what kind of "reload" you are talking about?
        I assume you mean the client's browser should reload at specific times:

        PHP can't reload a site, the browser does a reload if instructed to,
        therefore you need to tell the client's browser to reload the page, just
        add:

        <META HTTP-EQUIV=REFRESH CONTENT="10; URL=RCStudent.p hp">

        to your html head. Here the page is reloaded every 10 seconds

        PHP can redirect with header location like someone else just mentioned.
        And a redirect works only if you haven't echoed any html before doing a:

        header("Locatio n: ....);


        T. Wintershoven schrieb:
        Hi all,
        >
        Is there a simple way in php to reload a page coded within an if
        statement.(see code below)
        It's very important that the session stays intact.
        The filename is RCStudent.php
        >
        *************** * A peace of code*********** *************** *
        <?php
        session_start() ;
        ?>
        >
        if($_POST['ST']!='')
        {
        $_SESSION['nScreen']=2'';
        }
        elseif ($_POST['AT']!='')
        {
        $_SESSION['nScreen']=0'';
        >
        *** RELOAD CODE HERE ***
        }
        >
        *************** **** End code*********** *************** *****
        >
        T.i.a.
        >
        Regards,
        >
        Tino Wintershoven.
        The Netherlands.
        >
        >

        Comment

        • Christoph Burschka

          #5
          Re: Reload (refresh) page within an if statement

          You can't send a Location header after sending cookies (which
          session_start() does).

          So you either need to find a way to reload without starting a session,
          or you need to print a <metarefresh tag into the page to reload it...


          T. Wintershoven schrieb:
          Hi Shelly,
          >
          Thanks for your reaction.
          >
          When i do a header(location ), i get an error message:
          Warning: Cannot modify header information - headers already sent.
          >
          The header is allready sent on the second line ... session_start() ... (see
          code)
          >
          Tino
          >
          >
          >
          "Shelly" <sheldonlg.news @asap-consult.comwrot e in message
          news:9AVah.4038 $sf5.623@newsre ad4.news.pas.ea rthlink.net...
          >
          >>"T. Wintershoven" <twintershoven@ casema.nlwrote in message
          >>news:raqdnVvf toLyvfHYnZ2dnUV Z8tSdnZ2d@casem a.nl...
          >>
          >>>Hi all,
          >>>
          >>>Is there a simple way in php to reload a page coded within an if
          >>>statement.(s ee code below)
          >>>It's very important that the session stays intact.
          >>>The filename is RCStudent.php
          >>>
          >>>************ **** A peace of code*********** *************** *
          >>><?php
          >> session_start() ;
          >>>?>
          >>>
          >>>if($_POST['ST']!='')
          >>>{
          >> $_SESSION['nScreen']=2'';
          >>>}
          >>>elseif ($_POST['AT']!='')
          >>>{
          >> $_SESSION['nScreen']=0'';
          >>>
          >> *** RELOAD CODE HERE ***
          >>>}
          >>>
          >>>************ ******* End code*********** *************** *****
          >>
          >>Do a header("Locatio n: this_page_with_ appropiate_para meter_passing") ; ?
          >>
          >>Shelly
          >>
          >>
          >
          >
          >
          --
          CB

          Comment

          • Erwin Moller

            #6
            Re: Reload (refresh) page within an if statement

            Christoph Burschka wrote:
            You can't send a Location header after sending cookies (which
            session_start() does).
            >
            So you either need to find a way to reload without starting a session,
            or you need to print a <metarefresh tag into the page to reload it...
            Or you buffer the output by calling ob_start() at the start of the script.
            :-)

            Regards,
            Erwin Moller
            >
            >
            T. Wintershoven schrieb:
            >Hi Shelly,
            >>
            >Thanks for your reaction.
            >>
            >When i do a header(location ), i get an error message:
            >Warning: Cannot modify header information - headers already sent.
            >>
            >The header is allready sent on the second line ... session_start() ...
            >(see code)
            >>
            >Tino
            >>
            >>
            >>
            >"Shelly" <sheldonlg.news @asap-consult.comwrot e in message
            >news:9AVah.403 8$sf5.623@newsr ead4.news.pas.e arthlink.net...
            >>
            >>>"T. Wintershoven" <twintershoven@ casema.nlwrote in message
            >>>news:raqdnVv ftoLyvfHYnZ2dnU VZ8tSdnZ2d@case ma.nl...
            >>>
            >>>>Hi all,
            >>>>
            >>>>Is there a simple way in php to reload a page coded within an if
            >>>>statement.( see code below)
            >>>>It's very important that the session stays intact.
            >>>>The filename is RCStudent.php
            >>>>
            >>>>*********** ***** A peace of code*********** *************** *
            >>>><?php
            >>> session_start() ;
            >>>>?>
            >>>>
            >>>>if($_POST['ST']!='')
            >>>>{
            >>> $_SESSION['nScreen']=2'';
            >>>>}
            >>>>elseif ($_POST['AT']!='')
            >>>>{
            >>> $_SESSION['nScreen']=0'';
            >>>>
            >>> *** RELOAD CODE HERE ***
            >>>>}
            >>>>
            >>>>*********** ******** End code*********** *************** *****
            >>>
            >>>Do a header("Locatio n: this_page_with_ appropiate_para meter_passing") ; ?
            >>>
            >>>Shelly
            >>>
            >>>
            >>
            >>
            >>
            >
            --
            CB

            Comment

            • ED

              #7
              Re: Reload (refresh) page within an if statement


              "Christoph Burschka" <christoph.burs chka@rwth-aachen.dewrote in message
              news:4t2u5rF126 odiU1@mid.dfnci s.de...
              You can't send a Location header after sending cookies (which
              session_start() does).
              >
              So you either need to find a way to reload without starting a session, or
              you need to print a <metarefresh tag into the page to reload it...
              Um, you sure about that?
              The code below works fine here:

              <?php
              session_start() ;

              if (! isset($_GET['refresh'])) {
              setcookie('foo' ,'Bar');
              $_SESSION['foo'] = 'Bar';
              header('Locatio n:'.$_SERVER['PHP_SELF'].'?refresh=1');
              } else {
              echo 'page refreshed';
              echo '<br />Session foo: '.$_SESSION['foo'];
              echo '<br />Cookie foo: '.$_COOKIE['foo'];
              }
              ?>

              maybe the OP is outputting something (whitespace etc) prior to the
              redirection?

              cheers
              ED


              Comment

              • Christoph Burschka

                #8
                Re: Reload (refresh) page within an if statement

                ED wrote:
                "Christoph Burschka" <christoph.burs chka@rwth-aachen.dewrote in message
                news:4t2u5rF126 odiU1@mid.dfnci s.de...
                >You can't send a Location header after sending cookies (which
                >session_start( ) does).
                >>
                >So you either need to find a way to reload without starting a session, or
                >you need to print a <metarefresh tag into the page to reload it...
                >
                Um, you sure about that?
                The code below works fine here:
                >
                [...]
                >

                Then I remember it wrong...

                Oh, right: What you can't send after a cookie is the HTTP response code - such
                as "HTTP/1.1 303 See Other". The status code apparently has to be the first
                header sent, while the Location header can follow after the cookies just fine.

                I've never used a Location header without explicitly setting a 3xx response yet,
                so that's the reason for the mix-up.

                --
                Christoph Burschka

                Comment

                • Buddy

                  #9
                  Re: Reload (refresh) page within an if statement

                  You most definitely cannot use Header once you have output something to
                  the screen. I have had to battle that one a few times. It all depends
                  on where the php code is put in your page. If it has to be after
                  something is output (<bodytag) why not use JavaScript? If before
                  <bodyuse <meta>.

                  Christoph Burschka wrote:
                  ED wrote:
                  "Christoph Burschka" <christoph.burs chka@rwth-aachen.dewrote in message
                  news:4t2u5rF126 odiU1@mid.dfnci s.de...
                  You can't send a Location header after sending cookies (which
                  session_start() does).
                  >
                  So you either need to find a way to reload without starting a session, or
                  you need to print a <metarefresh tag into the page to reload it...
                  Um, you sure about that?
                  The code below works fine here:
                  [...]
                  >
                  >
                  Then I remember it wrong...
                  >
                  Oh, right: What you can't send after a cookie is the HTTP response code - such
                  as "HTTP/1.1 303 See Other". The status code apparently has to be the first
                  header sent, while the Location header can follow after the cookies just fine.
                  >
                  I've never used a Location header without explicitly setting a 3xx response yet,
                  so that's the reason for the mix-up.
                  >
                  --
                  Christoph Burschka

                  Comment

                  Working...