Setting a cookie?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tim Mousel
    Senior Member
    • May 2000
    • 281
    • 5.0.0

    Setting a cookie?

    Where do I place my setcookie code if I want to set a cookie when someone visits the index page?

    I'm having problems with header already being sent errors, so I'm obviously placing my code in the wrong place.

    Please help!
    Five Star Review Script - Add reviews to your website!
    Mixed Martial Arts - Houston MMA Training
    Women's Self-Defense - Courses and DVDs available
  • Chen
    Senior Member
    • Jun 2001
    • 8388

    #2
    You must call setcookie() before you send any output to the browser. If that's not possible, consider using output buffering:

    PHP Code:
    <?php

    echo "I'm printing stuff";

    // Yet I can set a cookie
    setcookie('cookieName''value');

    // Before output is kept in the buffer and not sent to the browser
    ob_end_flush();

    ?>
    Chen Avinadav
    Better to remain silent and be thought a fool than to speak out and remove all doubt.

    גם אני מאוכזב מסיקור תחרות לתור מוטור של NRG הרשת ע"י מעריב

    Comment

    widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
    Working...
    😀
    😂
    🥰
    😘
    🤢
    😎
    😞
    😡
    👍
    👎