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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.