Support » Fixing WordPress » Problems with setcookie and WP 2.6

  • Resolved nthnlsmmrs


    I’m having issues with :Cannot modify header information errors” and after trying just about everything I managed to track it down to one line of code:

    setcookie(“ftw_uid”, $uid, time()+3000000);

    After a few tests, I managed to figure out that I can’t set cookies at all, they all return that same error and the cookie is never set. If I delete or comment out those lines, then the error goes away. I’m hoping there’s a new setting somewhere that I need to switch. Any ideas?

    This is really killing the functionality of the site. I really depend on that one cookie to properly display affiliate links. Any help would be greatly appreciated.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Ok… it may be something else… and I’m not sure what.

    The problem may be with this entire chunk of code:

    $uid = 1;
    if($_COOKIE['ftw_uid'] != "") {
    $uid = $_COOKIE['ftw_uid'];
    elseif($_GET['uid'] != "") {
    $uid = $_GET['uid'];
    global $wpdb;
    $uid = $wpdb->get_var("SELECT * FROM $wpdb->users ORDER BY RAND() LIMIT 1");
    if(rand(0,1)) {
    $uid = 1;
    setcookie("ftw_uid", $uid, time()+3000000);

    I’m not sure what the deal could be though. It seems like I can set cookies from php files that this isn’t in. Do you think this might be a php version issue? I recently upgraded to 5… in an effort to fix a broken plugin… and issues with whitespace may have caused the cannot modify header errors from before. Who knows.

    Any suggestions?

    Alright, I don’t know what was going on, but by moving this code to before the page code even started, it managed to resolve the issue.

    Not sure, but it could be because of the cookie being set. Cookies are supposed to be set before the page output begins, I think. Not sure.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Problems with setcookie and WP 2.6’ is closed to new replies.