Header Processing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Call Me Tom

    Header Processing

    I was looking at an application with the following code snippet:

    ob_start();
    session_name('f oo');
    session_start() ;
    if (!$_SESSION['bar']) {
    header("Locatio n: http://" . $_SERVER['HTTP_HOST'] .
    dirname($_SERVE R['PHP_SELF']) . "/index.php");
    ob_end_clean();
    exit();
    }

    I am under the impression that the "header" redirection is immediate.
    Am I correct or will the 'ob_end_clean() ' and 'exit()' actually
    process.

    Tom
  • Erwin Moller

    #2
    Re: Header Processing


    Call Me Tom schreef:

    Hi Tom,
    I was looking at an application with the following code snippet:
    >
    ob_start();
    session_name('f oo');
    session_start() ;
    if (!$_SESSION['bar']) {
    header("Locatio n: http://" . $_SERVER['HTTP_HOST'] .
    dirname($_SERVE R['PHP_SELF']) . "/index.php");
    ob_end_clean();
    exit();
    }
    >
    I am under the impression that the "header" redirection is immediate.
    That is wrong.
    This is not like, for example ASP/VB's Response.Redire ct.
    header() function in PHP does excact what it says and nothing more:
    Setting a header.
    Am I correct or will the 'ob_end_clean() ' and 'exit()' actually
    process.
    They will be processed.
    >
    Tom
    Bottomline: If you need a 'redirect' via header("Locatio n...") always
    call exit after that, or the script will merely run on untill it ends.

    Regards,
    Erwin Moller

    --
    =============== =============
    Erwin Moller
    Now dropping all postings from googlegroups.
    Why? http://improve-usenet.org/
    =============== =============

    Comment

    • Jerry Stuckle

      #3
      Re: Header Processing

      Erwin Moller wrote:
      >
      Call Me Tom schreef:
      >
      Hi Tom,
      >
      >I was looking at an application with the following code snippet:
      >>
      >ob_start();
      >session_name(' foo');
      >session_start( );
      >if (!$_SESSION['bar']) { header("Locatio n: http://" .
      >$_SERVER['HTTP_HOST'] . dirname($_SERVE R['PHP_SELF']) .
      >"/index.php");
      > ob_end_clean();
      > exit();
      >}
      >>
      >I am under the impression that the "header" redirection is immediate.
      >
      That is wrong.
      This is not like, for example ASP/VB's Response.Redire ct.
      header() function in PHP does excact what it says and nothing more:
      Setting a header.
      >
      >Am I correct or will the 'ob_end_clean() ' and 'exit()' actually
      >process.
      >
      They will be processed.
      >
      >>
      >Tom
      >
      Bottomline: If you need a 'redirect' via header("Locatio n...") always
      call exit after that, or the script will merely run on untill it ends.
      >
      Regards,
      Erwin Moller
      >
      Almost correct, Erwin,

      The script will continue until the redirect actually takes place. That
      will be after the header is sent to the client and the client responds.

      So while the rest of this script will run, another script with a
      relatively long run time probably will be interrupted.

      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstucklex@attgl obal.net
      =============== ===

      Comment

      • Erwin Moller

        #4
        Re: Header Processing


        Jerry Stuckle schreef:
        Erwin Moller wrote:
        >>
        >Call Me Tom schreef:
        >>
        >Hi Tom,
        >>
        >>I was looking at an application with the following code snippet:
        >>>
        >>ob_start();
        >>session_name( 'foo');
        >>session_start ();
        >>if (!$_SESSION['bar']) { header("Locatio n: http://" .
        >>$_SERVER['HTTP_HOST'] . dirname($_SERVE R['PHP_SELF']) .
        >>"/index.php");
        >> ob_end_clean();
        >> exit();
        >>}
        >>>
        >>I am under the impression that the "header" redirection is immediate.
        >>
        >That is wrong.
        >This is not like, for example ASP/VB's Response.Redire ct.
        >header() function in PHP does excact what it says and nothing more:
        >Setting a header.
        >>
        >>Am I correct or will the 'ob_end_clean() ' and 'exit()' actually
        >>process.
        >>
        >They will be processed.
        >>
        >>>
        >>Tom
        >>
        >Bottomline: If you need a 'redirect' via header("Locatio n...") always
        >call exit after that, or the script will merely run on untill it ends.
        >>
        >Regards,
        >Erwin Moller
        >>
        >
        Almost correct, Erwin,
        >
        The script will continue until the redirect actually takes place. That
        will be after the header is sent to the client and the client responds.
        >
        So while the rest of this script will run, another script with a
        relatively long run time probably will be interrupted.
        >
        Hi Jerry,

        Good point, Jerry.
        If a programmer WANTS to keep executing the script after the
        locationheader (some longrunning DB actions eg), this might cause some
        hard-to-find bugs.
        Since the time the remainder of the scripts has depends on the speed to
        the client.

        Since I never leave my script running after a Location header, I never
        gave that route of problems much thought. ;-)

        Hypothetical question: Suppose I deliberately want to keep the script
        running after the header("Locatio n.."), will using
        ignore_user_abo rt(TRUE) avoid this problem?

        Regards,
        Erwin Moller


        --
        =============== =============
        Erwin Moller
        Now dropping all postings from googlegroups.
        Why? http://improve-usenet.org/
        =============== =============

        Comment

        • Jerry Stuckle

          #5
          Re: Header Processing

          Erwin Moller wrote:
          >
          Jerry Stuckle schreef:
          >Erwin Moller wrote:
          >>>
          >>Call Me Tom schreef:
          >>>
          >>Hi Tom,
          >>>
          >>>I was looking at an application with the following code snippet:
          >>>>
          >>>ob_start() ;
          >>>session_name ('foo');
          >>>session_star t();
          >>>if (!$_SESSION['bar']) { header("Locatio n: http://" .
          >>>$_SERVER['HTTP_HOST'] . dirname($_SERVE R['PHP_SELF']) .
          >>>"/index.php");
          >>> ob_end_clean();
          >>> exit();
          >>>}
          >>>>
          >>>I am under the impression that the "header" redirection is immediate.
          >>>
          >>That is wrong.
          >>This is not like, for example ASP/VB's Response.Redire ct.
          >>header() function in PHP does excact what it says and nothing more:
          >>Setting a header.
          >>>
          >>>Am I correct or will the 'ob_end_clean() ' and 'exit()' actually
          >>>process.
          >>>
          >>They will be processed.
          >>>
          >>>>
          >>>Tom
          >>>
          >>Bottomline: If you need a 'redirect' via header("Locatio n...") always
          >>call exit after that, or the script will merely run on untill it ends.
          >>>
          >>Regards,
          >>Erwin Moller
          >>>
          >>
          >Almost correct, Erwin,
          >>
          >The script will continue until the redirect actually takes place.
          >That will be after the header is sent to the client and the client
          >responds.
          >>
          >So while the rest of this script will run, another script with a
          >relatively long run time probably will be interrupted.
          >>
          >
          Hi Jerry,
          >
          Good point, Jerry.
          If a programmer WANTS to keep executing the script after the
          locationheader (some longrunning DB actions eg), this might cause some
          hard-to-find bugs.
          Since the time the remainder of the scripts has depends on the speed to
          the client.
          >
          Since I never leave my script running after a Location header, I never
          gave that route of problems much thought. ;-)
          >
          Hypothetical question: Suppose I deliberately want to keep the script
          running after the header("Locatio n.."), will using
          ignore_user_abo rt(TRUE) avoid this problem?
          >
          Regards,
          Erwin Moller
          >
          >
          Yep, it should, but I would say no guarantee - the web server may
          terminate the thread (although I don't know of any cases where it will
          for sure). But it would be better to just delay the header() call, if
          possible, or start another script as a background task. Then you're
          more sure it will not be killed.

          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          Working...