Please help. That darn header command

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

    Please help. That darn header command

    I'm hoping someone can help me with this. I've seen and tried various
    solutions I've seen on the net, but nothing works.

    Of course it works perfectly on localhost, but when I upload it to the
    server (1and1.com) it gives errors. The user enters a code, the code is
    verified, a new one is created and it's supposed to send them to the next
    page.
    if (CodeExist($cCo de) > 0){
    $cNewCode = MakeCode();
    $ok = InsertRec($cNew Code);

    ob_start(); // doesn't matter if I leave this in or take it out.
    session_cache_l imiter('public' ); // suggestion from the internet. No
    effect :(
    session_start() ;
    $_SESSION['newcode'] = $cNewCode;

    print "session is set to:".$_SESSION['newcode'];
    header("Locatio n: info.php");
    exit;

    And here's the output. Notice that the session was set even through the
    error messages:

    Warning: Cannot send session cookie - headers already sent by (output
    started at /devel/joinnow.php:4) in /devel/joinnow.php on line 20

    Warning: Cannot send session cache limiter - headers already sent (output
    started at /devel/joinnow.php:4) in /devel/joinnow.php on line 20
    session is set to:JSG598
    Warning: Cannot add header information - headers already sent by (output
    started at /devel/joinnow.php:4) in /devel/joinnow.php on line 25

    Any help would be extremely helpful!
    Thanks!!


  • Lochness

    #2
    Re: Please help. That darn header command

    Update! I created two php test pages. Page 1 redirected to page 2. It
    worked on my localhost AND on the internet server. So I'm scratching my
    head thinking "What the hell?". THEN I tried it using my Dreamweaver
    template. Holy crap, the simple one line redirection worked on my
    localhost, but not on the internet server.

    The Dreamweaver template is causing the mess!! Has any one else experienced
    this and figured out how to fix it?

    "Lochness" <someone@somewh ere.com> wrote in message
    news:mOIcc.3723 9$Pk3.11329@pd7 tw1no...[color=blue]
    > I'm hoping someone can help me with this. I've seen and tried various
    > solutions I've seen on the net, but nothing works.
    >
    > Of course it works perfectly on localhost, but when I upload it to the
    > server (1and1.com) it gives errors. The user enters a code, the code is
    > verified, a new one is created and it's supposed to send them to the next
    > page.
    > if (CodeExist($cCo de) > 0){
    > $cNewCode = MakeCode();
    > $ok = InsertRec($cNew Code);
    >
    > ob_start(); // doesn't matter if I leave this in or take it out.
    > session_cache_l imiter('public' ); // suggestion from the internet. No
    > effect :(
    > session_start() ;
    > $_SESSION['newcode'] = $cNewCode;
    >
    > print "session is set to:".$_SESSION['newcode'];
    > header("Locatio n: info.php");
    > exit;
    >
    > And here's the output. Notice that the session was set even through the
    > error messages:
    >
    > Warning: Cannot send session cookie - headers already sent by (output
    > started at /devel/joinnow.php:4) in /devel/joinnow.php on line 20
    >
    > Warning: Cannot send session cache limiter - headers already sent (output
    > started at /devel/joinnow.php:4) in /devel/joinnow.php on line 20
    > session is set to:JSG598
    > Warning: Cannot add header information - headers already sent by (output
    > started at /devel/joinnow.php:4) in /devel/joinnow.php on line 25
    >
    > Any help would be extremely helpful!
    > Thanks!!
    >
    >[/color]


    Comment

    • Jan Pieter Kunst

      #3
      Re: Please help. That darn header command

      In article <xvLcc.40778$Ig .8376@pd7tw2no> ,
      "Lochness" <someone@somewh ere.com> wrote:
      [color=blue]
      > The Dreamweaver template is causing the mess!! Has any one else experienced
      > this and figured out how to fix it?[/color]

      Probably empty lines or spaces somewhere. If you do a header("Locatio n:
      "), there is no output of any sort allowed before that. And that
      includes white space before the <?php declaration.

      JP

      --
      Sorry, <devnull@cauce. org> is een "spam trap".
      E-mail adres is <jpk"at"akamail .com>, waarbij "at" = @.

      Comment

      • Rob

        #4
        Re: Please help. That darn header command


        "Jan Pieter Kunst" <devnull@cauce. org> schreef in bericht
        news:devnull-1917AC.07400107 042004@news1.ne ws.xs4all.nl...[color=blue]
        > In article <xvLcc.40778$Ig .8376@pd7tw2no> ,
        > "Lochness" <someone@somewh ere.com> wrote:
        >[color=green]
        > > The Dreamweaver template is causing the mess!! Has any one else[/color][/color]
        experienced[color=blue][color=green]
        > > this and figured out how to fix it?[/color]
        >
        > Probably empty lines or spaces somewhere. If you do a header("Locatio n:
        > "), there is no output of any sort allowed before that. And that
        > includes white space before the <?php declaration.
        >
        > JP
        >
        > --
        > Sorry, <devnull@cauce. org> is een "spam trap".
        > E-mail adres is <jpk"at"akamail .com>, waarbij "at" = @.[/color]

        <snip> from previous post

        if (CodeExist($cCo de) > 0){
        $cNewCode = MakeCode();
        $ok = InsertRec($cNew Code);

        ob_start(); // doesn't matter if I leave this in or take it out.
        session_cache_l imiter('public' ); // suggestion from the internet. No
        effect :(
        session_start() ;
        $_SESSION['newcode'] = $cNewCode;

        print "session is set to:".$_SESSION['newcode'];
        header("Locatio n: info.php");
        exit;

        </snip>

        It is not probably it is definitely. Look at the print statement.
        If you want to change the header information then this is the first thing
        send back to the client. When sending white spaces, using echo's or print
        statements the header information is automatically send. The message:
        "Warning: Cannot send session cache limiter - headers already sent" is
        telling you did send something before using the header function. it is even
        telling you where you did this (hence the line "/devel/joinnow.php on line
        20").

        I don't know where you got your suggestions or other information from the
        internet but www.php.net is a good place to start. Look at
        http://www.php.net/manual/nl/function.header.php first ;-)


        HTH rob


        Comment

        • Centurion

          #5
          Re: Please help. That darn header command

          Lochness wrote:
          [color=blue]
          > Update! I created two php test pages. Page 1 redirected to page 2. It
          > worked on my localhost AND on the internet server. So I'm scratching my
          > head thinking "What the hell?". THEN I tried it using my Dreamweaver
          > template. Holy crap, the simple one line redirection worked on my
          > localhost, but not on the internet server.
          >
          > The Dreamweaver template is causing the mess!! Has any one else
          > experienced this and figured out how to fix it?[/color]

          Don't use Dreamweaver? Seriously the only stuff I'd trust to use
          'auto-code' for is flat, boring, static HTML. I've seen all sorts of
          weirdness and client incompatibility from code generated in various IDE's
          (Like Dreamweaver). Unless you are stuck with it, maybe try hand-cranking
          your code 'ye olde fashioned' way.

          Not much help, I know, but thought I'd throw my $0.02 in.

          Good luck,

          James
          --
          Fortune cookie says:
          Do unto others before they undo you.

          Comment

          • Lochness

            #6
            Re: Please help. That darn header command

            Thank you so much guys!!
            After reading your replies I created a little test. With my template I
            created a one statement page and at the top added:
            --------------------
            <?php error_reporting (E_ALL);?>

            <?php
            header("Locatio n: test2.htm");
            ?>
            --------------------
            Notice the white space between the two php statements. I sent it up
            to my server and it crashed. So I took out the whitespace, sent it up
            to my server and it worked!! Then on my big program, I took out all
            the blank lines and commented out the print statement. Tada! It
            worked!! So thanks to you guys and grrrr to php and it's tightass
            attitude towards whitespace.

            It worked on my localhost which is version 4.3.4 and the server is
            4.2.3. Maybe the newer version isn't as anal about whitespace.

            Anyways. Thanks again!!

            "Rob" <reply_@news_gr oup.please> wrote in message news:<efOcc.136 868$pN4.94344@a msnews03.chello .com>...[color=blue]
            > "Jan Pieter Kunst" <devnull@cauce. org> schreef in bericht
            > news:devnull-1917AC.07400107 042004@news1.ne ws.xs4all.nl...[color=green]
            > > In article <xvLcc.40778$Ig .8376@pd7tw2no> ,
            > > "Lochness" <someone@somewh ere.com> wrote:
            > >[color=darkred]
            > > > The Dreamweaver template is causing the mess!! Has any one else[/color][/color]
            > experienced[color=green][color=darkred]
            > > > this and figured out how to fix it?[/color]
            > >
            > > Probably empty lines or spaces somewhere. If you do a header("Locatio n:
            > > "), there is no output of any sort allowed before that. And that
            > > includes white space before the <?php declaration.
            > >
            > > JP
            > >
            > > --
            > > Sorry, <devnull@cauce. org> is een "spam trap".
            > > E-mail adres is <jpk"at"akamail .com>, waarbij "at" = @.[/color]
            >
            > <snip> from previous post
            >
            > if (CodeExist($cCo de) > 0){
            > $cNewCode = MakeCode();
            > $ok = InsertRec($cNew Code);
            >
            > ob_start(); // doesn't matter if I leave this in or take it out.
            > session_cache_l imiter('public' ); // suggestion from the internet. No
            > effect :(
            > session_start() ;
            > $_SESSION['newcode'] = $cNewCode;
            >
            > print "session is set to:".$_SESSION['newcode'];
            > header("Locatio n: info.php");
            > exit;
            >
            > </snip>
            >
            > It is not probably it is definitely. Look at the print statement.
            > If you want to change the header information then this is the first thing
            > send back to the client. When sending white spaces, using echo's or print
            > statements the header information is automatically send. The message:
            > "Warning: Cannot send session cache limiter - headers already sent" is
            > telling you did send something before using the header function. it is even
            > telling you where you did this (hence the line "/devel/joinnow.php on line
            > 20").
            >
            > I don't know where you got your suggestions or other information from the
            > internet but www.php.net is a good place to start. Look at
            > http://www.php.net/manual/nl/function.header.php first ;-)
            >
            >
            > HTH rob[/color]

            Comment

            • Markus Ernst

              #7
              Re: Please help. That darn header command

              "Lochness" <s1p2a3m4@hotma il.com> schrieb im Newsbeitrag
              news:acd5bf90.0 404070904.16410 559@posting.goo gle.com...[color=blue]
              > Thank you so much guys!!
              > After reading your replies I created a little test. With my template I
              > created a one statement page and at the top added:
              > --------------------
              > <?php error_reporting (E_ALL);?>
              >
              > <?php
              > header("Locatio n: test2.htm");
              > ?>
              > --------------------
              > Notice the white space between the two php statements. I sent it up
              > to my server and it crashed. So I took out the whitespace, sent it up
              > to my server and it worked!! Then on my big program, I took out all
              > the blank lines and commented out the print statement. Tada! It
              > worked!! So thanks to you guys and grrrr to php and it's tightass
              > attitude towards whitespace.
              >
              > It worked on my localhost which is version 4.3.4 and the server is
              > 4.2.3. Maybe the newer version isn't as anal about whitespace.
              >
              > Anyways. Thanks again!![/color]

              I am not understanding everything about that stuff, but I am quite sure that
              your problem is not about PHP but about HTTP. HTTP headers can't be sent
              after any output, regardless of what technique you use to send them. So if
              you do this:

              <?php
              // PHP code
              ?>

              <?php header("myheade r"); ?>

              you output white space via HTTP (and thus send the headers) in an area that
              is not controlled by PHP.

              If you do this:

              <?
              php echo "something" ;
              header("myheade r");
              ?>

              your output is also sent via HTTP. I am quite sure that a clean arrangement
              of the code in most cases solves that problem easily. For login or session
              stuff I usually do it the way:

              <?php
              // handle session, check login, send cookie or whatever
              $loggedin = "no"; // set variable with the result of the above actions
              $message = "Wrong password, try it again!"; // set message according to the
              above actions
              ?>
              <html>
              <head></head>
              <body>
              <?php
              if($loggedin==" no") {
              echo $message;
              // display loginform
              }
              else {
              // display contents
              }
              ?>
              </body>
              </html>

              Maybe your task is different, but you see the principle.

              HTH
              Markus


              Comment

              Working...