Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6236073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:47:10+00:00 2026-05-24T10:47:10+00:00

When I set a cookie in a WordPress plugin, I get the headers already

  • 0

When I set a cookie in a WordPress plugin, I get the “headers already sent” error. Can someone suggest how I can fix this?

Warning: Cannot modify header information – headers already sent by (output started at /home/content/53/7742253/html/wordpress/wp-content/themes/twentyten/header.php:11) in /home/content/53/7742253/html/wordpress/wp-includes/pluggable.php on line 692,693,694

my code:-

     if(isset($_REQUEST['id']) && !is_user_logged_in())

      {

         require_once( ABSPATH . WPINC . '/registration.php' );


    $registration = get_option( 'users_can_register' );

       global $wpdb;

       $user_id = $wpdb->get_var( $wpdb->prepare("SELECT user_id FROM              

                  $wpdb->usermeta           WHERE 

                meta_key = 'id' AND meta_value =%s",$id) );

         if ( empty($user_id) ) 
              {

                 $wp_user_obj = get_user_by('email', $email);

                $user_id = $wp_user_obj->ID;

               }

               if ( $user_id)

                  {

                   wp_set_auth_cookie( $user_id );

                      wp_set_current_user( $user_id );

               if ( isset( $_REQUEST['redirect_to'] ) && !empty( 
           $_REQUEST['redirect_to'] ) ) 
            {

              wp_redirect( home_url() );

                 }
                 else 
               {

                wp_redirect(home_url() );

                 }

                   }      

                     else

                   {

                   $userdata = array();


                $user_id = wp_insert_user($userdata );

                 wp_new_user_notification($user_id,$user_pass);

                  if ( $user_id )
                     {

                         $creds = array();

                        $creds['user_login'] = $username;

                         $creds['user_password'] = $user_pass;

                          if ( !empty( $remember ) )
                            { 

                             $creds['remember'] = true;

                                 }

                    $user = wp_signon( $creds, true );  

                     update_usermeta( $user_id,'id',esc_attr( $_REQUEST['id']));

                 update_usermeta( $user_id,'fname',esc_attr( $_REQUEST['fname']));

                   update_usermeta( $user_id,'lname',$_REQUEST['lname']);

              update_usermeta( $user_id, 'email',esc_attr( $_REQUEST['email']) );

                 wp_redirect(home_url() );

               }

                }

               }    

             global $user_ID; $user = get_userdata( $user_ID );

           if(is_user_logged_in())
         {

                echo $user->user_login ; 

              } 



and heder.php line:-  `<html <?php language_attributes(); ?>>`
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:47:12+00:00Added an answer on May 24, 2026 at 10:47 am

    You’re calling your set_cookies function too late. At the time you call it, output has already started. You need call it before any output has started, because cookies can not be set if output has already started (see as well: setcookieDocs).

    In your case before header.php line 11 is being executed.

    That’s merely before the theme get’s loaded.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(Note: See also the related question Can browsers react to Set-Cookie specified in headers
How can I set, get and destroy cookies in WordPress? I surfed the web
I am hoping someone can help me this this problem. I know how to
I'm using cookie plugin with jquery. I set cookie like $.cookie('key','value') . In firebug
Hi I have a problem with set cookie. I have a url like this
I am using to set cookie on user login $a = setcookie($this->remCookieName,$cookie, time() +
If there is a cookie set for a subdomain, metric.foo.com, is there a way
I'd like to set a cookie via Django with that has several different values
How do you delete a cookie in rails that was set with a wild
How can I set the cookies in my PHP apps as HttpOnly cookies ?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.