Headers, session, include, - and header again?

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

    #1

    Headers, session, include, - and header again?

    Hi all!

    I have this problem, that I need to check the user (using session data
    and some checks (included files)), then when ok, I can send a file to
    the user.... meaning (simplified):

    header("Pragma: no-cache");
    header("Expires : -1");

    session_start() ;
    if($_SERVER['QUERY_STRING']=="logout")
    session_unset() ;

    include("sessio n_control.php") ;
    include('classe s.php');

    then, if needed, I might try this (sending a generated file to the
    user):

    header('Content-type: application/octet-stream');
    header("Content-Disposition: attachment; filename=\"$fil ename\"");
    readfile($userf ile);

    But, I cannot set the headers any more. Then again, I need the
    $_SESSION information to check this first, and I need some included
    functions to do that.

    The very ugly solution is all code in one file. There must be another
    way....

    Any idea how to overcome this?

    WBR
    Sonnich
  • Rik Wasmus

    #2
    Re: Headers, session, include, - and header again?

    On Tue, 04 Dec 2007 08:02:57 +0100, jodleren <sonnich@hot.ee wrote:
    Hi all!
    >
    I have this problem, that I need to check the user (using session data
    and some checks (included files)), then when ok, I can send a file to
    the user.... meaning (simplified):
    >
    header("Pragma: no-cache");
    header("Expires : -1");
    >
    session_start() ;
    if($_SERVER['QUERY_STRING']=="logout")
    session_unset() ;
    >
    include("sessio n_control.php") ;
    include('classe s.php');
    >
    then, if needed, I might try this (sending a generated file to the
    user):
    >
    header('Content-type: application/octet-stream');
    header("Content-Disposition: attachment; filename=\"$fil ename\"");
    readfile($userf ile);
    >
    But, I cannot set the headers any more. Then again, I need the
    $_SESSION information to check this first, and I need some included
    functions to do that.
    >
    The very ugly solution is all code in one file. There must be another
    way....
    >
    Any idea how to overcome this?
    Includes are not the reason you can't send any headers anymore. They fact
    that they produce output is. So, take care of that, strip all output from
    the included files that shouldn't be there (especially look for whitespace
    outside of php tags if the problem persists). Normally, PHP will inform
    you where the output started.
    --
    Rik Wasmus

    Comment

    • jodleren

      #3
      Re: Headers, session, include, - and header again?

      On Dec 4, 9:06 am, "Rik Wasmus" <luiheidsgoe... @hotmail.comwro te:
      On Tue, 04 Dec 2007 08:02:57 +0100, jodleren <sonn...@hot.ee wrote:
      Hi all!
      >
      I have this problem, that I need to check the user (using session data
      ....
      Any idea how to overcome this?
      >
      Includes are not the reason you can't send any headers anymore. They fact
      that they produce output is. So, take care of that, strip all output from
      the included files that shouldn't be there (especially look for whitespace
      outside of php tags if the problem persists). Normally, PHP will inform
      you where the output started.
      Thanks, that was it.

      WBR
      Sonnich

      Comment

      • AnrDaemon

        #4
        Re: Headers, session, include, - and header again?

        Greetings, jodleren.
        In reply to Your message dated Tuesday, December 4, 2007, 10:02:57,
        I have this problem, that I need to check the user (using session data
        and some checks (included files)), then when ok, I can send a file to
        the user.... meaning (simplified):
        header("Pragma: no-cache");
        header("Expires : -1");
        session_start() ;
        if($_SERVER['QUERY_STRING']=="logout")
        session_unset() ;
        include("sessio n_control.php") ;
        include('classe s.php');
        then, if needed, I might try this (sending a generated file to the
        user):
        header('Content-type: application/octet-stream');
        header("Content-Disposition: attachment; filename=\"$fil ename\"");
        readfile($userf ile);
        But, I cannot set the headers any more. Then again, I need the
        $_SESSION information to check this first, and I need some included
        functions to do that.
        The very ugly solution is all code in one file. There must be another
        way....
        Any idea how to overcome this?
        One more idea - enable output buffering.


        --
        Sincerely Yours, AnrDaemon <anrdaemon@free mail.ru>

        Comment

        • Rik Wasmus

          #5
          Re: Headers, session, include, - and header again?

          On Wed, 05 Dec 2007 16:47:51 +0100, AnrDaemon <anrdaemon@free mail.ru
          wrote:
          Greetings, jodleren.
          In reply to Your message dated Tuesday, December 4, 2007, 10:02:57,
          >
          >I have this problem, that I need to check the user (using session data
          >and some checks (included files)), then when ok, I can send a file to
          >the user.... meaning (simplified):
          >
          > header("Pragma: no-cache");
          > header("Expires : -1");
          >
          > session_start() ;
          > if($_SERVER['QUERY_STRING']=="logout")
          > session_unset() ;
          >
          > include("sessio n_control.php") ;
          > include('classe s.php');
          >
          >then, if needed, I might try this (sending a generated file to the
          >user):
          >
          > header('Content-type: application/octet-stream');
          > header("Content-Disposition: attachment; filename=\"$fil ename\"");
          > readfile($userf ile);
          >
          >But, I cannot set the headers any more. Then again, I need the
          >$_SESSION information to check this first, and I need some included
          >functions to do that.
          >
          >The very ugly solution is all code in one file. There must be another
          >way....
          >
          >Any idea how to overcome this?
          >
          One more idea - enable output buffering.
          Which is, 99% of the time it's used to be able to send headers, just
          obscuring a fault in the design of the script. It works, it's just not
          good practise.
          --
          Rik Wasmus

          Comment

          • AnrDaemon

            #6
            Re: Headers, session, include, - and header again?

            Greetings, Rik Wasmus.
            In reply to Your message dated Wednesday, December 5, 2007, 19:01:25,
            Which is, 99% of the time it's used to be able to send headers, just
            obscuring a fault in the design of the script. It works, it's just not
            good practise.
            Using page compression You're forced to use buffering anyway.
            So not a big deal (But youre in fact right)


            --
            Sincerely Yours, AnrDaemon <anrdaemon@free mail.ru>

            Comment

            Working...