WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Problems with setcookie and WP 2.6 (4 posts)

  1. nthnlsmmrs
    Member
    Posted 5 years ago #

    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.

  2. nthnlsmmrs
    Member
    Posted 5 years ago #

    Ok... it may be something else... and I'm not sure what.

    The problem may be with this entire chunk of code:

    <?php
    $uid = 1;
    if($_COOKIE['ftw_uid'] != "") {
    $uid = $_COOKIE['ftw_uid'];
    }
    elseif($_GET['uid'] != "") {
    $uid = $_GET['uid'];
    }
    else
    {
    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?

  3. nthnlsmmrs
    Member
    Posted 5 years ago #

    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.

  4. whoisvaibhav
    Member
    Posted 4 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic