Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I put simple php condition in the header.php of template as this :

setcookie("test_time_".$cookie_id."", $cookies_times, time()+3600);

The result always as this headers already sent , i use this inside plugin and also i try outside the plugin and the result always the same

It´s possible use cookies in header or what can i do for fix this problem , i need use cookies for works little function

share|improve this question

1 Answer 1

The issue you have appears because you set your cookies too late. You have to set it before anything will be rendered. Set your cookies in the your-plugin-file.php file.

Also you can check if headers were sent or not by calling headers_sent() function:

add_action( 'init', 'wpse8170_init' );
function wpse8170_init() {
    if ( !headers_sent() ) {
        setcookie("test_time_".$cookie_id."", $cookies_times, time()+3600);
    }
}
share|improve this answer
    
The probem i use plugin and i don´t know how i can do this , how i can include this from plugin in header ? , thak´s –  user2501504 Oct 10 '13 at 15:21
    
I have updated my answer, check it now –  Eugene Manuilov Oct 10 '13 at 15:23
    
OK very nice thank´s –  user2501504 Oct 10 '13 at 16:54
    
If you think that the answer is correct, then mark it as it is. –  Eugene Manuilov Oct 10 '13 at 16:55
    
Yes , one thing more please , if i have for example one file in my plugin called code.php how i can insert in header this file from plugin it´s my last question , thank´s regards !!! –  user2501504 Oct 10 '13 at 17:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.