Header information?

Discussion in 'PHP' started by D_C, Jan 30, 2008.

  1. #1
    I'm trying to set up a cookie, and this is the portion of the script it pertains to:

    
    echo "Makeing Cookie...";
    setcookie("user", "$uname", time()+3600) or die("Cookie not made.");
    echo "Cookie Made.";
    
    Code (markup):
    For some reason, I'm getting this error:
    On line 10:
    
    <?
    
    Code (markup):
    I'm not sure what the problem is. Anyone help me please?
     
    D_C, Jan 30, 2008 IP
  2. shallowink

    shallowink Well-Known Member

    Messages:
    1,218
    Likes Received:
    64
    Best Answers:
    2
    Trophy Points:
    150
    #2
    Cookies have to be set before anything is displayed in the browser. So if you have HTML, the php code has to go before it. If you echo or print anything with PHP, the cookie has to go first....Have to guess, since it's just a code snippet.
     
    shallowink, Jan 30, 2008 IP
  3. D_C

    D_C Well-Known Member

    Messages:
    1,107
    Likes Received:
    21
    Best Answers:
    1
    Trophy Points:
    160
    #3
    I see, looks like I will be learning sessions then. Thanks.
     
    D_C, Jan 30, 2008 IP
  4. fairuz.ismail

    fairuz.ismail Peon

    Messages:
    232
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Session have to be set before anything is displayed in the browser too. =)
     
    fairuz.ismail, Jan 30, 2008 IP
  5. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #5
    Unless you use AJAX.
     
    Kaizoku, Jan 30, 2008 IP
  6. fairuz.ismail

    fairuz.ismail Peon

    Messages:
    232
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #6
    maybe you can check on line 10, because a single space can cause this error..so beware when you use sessions or cookies for your website..

    easy example;

    <?php   (there are no extra spaces here)
     <?php (but this one has extra spaces!)
    PHP:
     
    fairuz.ismail, Jan 31, 2008 IP