cookie and header error

Discussion in 'PHP' started by promotingspace.net, Mar 19, 2008.

  1. #1
    Hi
    is setting cookie sending output?
    I get this error:
    Warning: Cannot modify header information - headers already sent by (output started at /home/pw64/public_html/sitesaz/regt.php:8) in /home/pw64/public_html/members/saleconfirmed.php on line 37
    line 37 is :
    36  $past = time() - 3600; 
    37  setcookie('refferer', $userid, $past); 
    Code (markup):
    and i cannot chage this line or line 8. is there a solution?
     
    promotingspace.net, Mar 19, 2008 IP
  2. AsHinE

    AsHinE Well-Known Member

    Messages:
    240
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    138
    #2
    No, php is telling you that something has been sent to browser on line 8 of regt.php.
    And setting cookie is made through sending a header like this:
    
    Set-Cookie: SS=Q0=aW5mbzpodHRwOi8vd3d3Lmdvb2dsZS5ydS8; path=/search
    
    Code (markup):
    So you get this error - script can not set cookie.
     
    AsHinE, Mar 19, 2008 IP
  3. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #3
    There is an easy fix.

    If you add this to the very top of the page (no space or line break above it) it should be ok

    <?php
    ob_start();
    ?>
    PHP:
     
    stephan2307, Mar 20, 2008 IP