Jump to content

cant get cookies to work, getting frustrated.


turkman

Recommended Posts

in my index page the first thing i do is call set_id();

 

this is the code for set_id

function set_id(){
        
        add_notice("in set id");
        if(isset($_COOKIE['supercookie'])){
        
                  $v =$_COOKIE['supercookie'];
                  //update cookie
                  setcookie("supercookie",$v,time() + 60 * 60 * 24 * 365);
                  add_notice("cookie was set");
        
        }
        else{
        $charlist =  "abcdefghijklmnopqrstuvwxyz0123456789";
        $c = "";
        
        for($i = 0; $i < 25; $i++ ){
        
              
              $r = rand() % strlen($charlist);
              $c .= $charlist[$r];
        
        
        }
        add_notice("Tried to create cookie: $c");
        setcookie("supercookie",$c,time() + 60 * 60 * 24 * 365);
        addaction(9,"Set New id.");
        }
        

}

 

 

no matter how many times i refresh the page - it still doesnt register when i test for cookies if(isset($_COOKIE('supercookie')))

 

i set my site up, its anonymous but it keeps track of people for bans etc using cookies, but no matter what browser i try it in cookies dont work and i set my site up for safety reasons that you could only try to log in to the admin area if you had a cookie, so i cant even get into the admin area of my site.

 

i dont know why this wont work.

 

Are you developing and debugging your code on a system with error_reporting set to E_ALL and display_errors set to ON so that all the errors that php detects, like a header error that would prevent cookies from working, will be reported and displayed? You will save a TON of time.

oh thats displaying errors now the error i get is  Warning: Cannot modify header information - headers already sent by (output started at /home/imgboard/public_html/mushphp/includes/top.php:9) in /home/imgboard/public_html/mushphp/includes/functions.php on line 706

 

which corresponds with the the code i posted above the setcookie() line... whats causing the error?

Unfortunately, your development system has output_buffering turned on in the master php.ini, so code you develop won't necessarily work on your live server. I recommend turning output_buffering off so that code you develop will work on the widest range of servers.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.