Title: Using setcookie in a plugin
Last modified: August 19, 2016

---

# Using setcookie in a plugin

 *  [dibbit](https://wordpress.org/support/users/dibbit/)
 * (@dibbit)
 * [15 years, 6 months ago](https://wordpress.org/support/topic/using-setcookie-in-a-plugin/)
 * I am writing a plugin that needs to use a cookie to track if a user has completed
   a survey. The plugin runs from a shortcode placed on a page. My problem is that
   as the shortcode is executed after the headers are sent I can’t set the cookie–
   well at least I think that is why it is going wrong. This is the error message
   I get:
 * Warning: Cannot modify header information – headers already sent by (output started
   at /home/mynerjac/public_html/frbf/wp-content/plugins/all-in-one-seo-pack/aioseop.
   class.php:221)…
 * Any ideas how I can get round this?
 * This is the code I am using to set the cookie (and nothing has been echoed before
   this code):
 *     ```
       $expire=time()+60*60*24*30;  //Expires in one month
       	$url = parse_url(get_option('home'));
       	setcookie( $cookie_name, "done", $expire, $url['path'] . '/');
       ```
   

The topic ‘Using setcookie in a plugin’ is closed to new replies.

## Tags

 * [cookies](https://wordpress.org/support/topic-tag/cookies/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 0 replies
 * 1 participant
 * Last reply from: [dibbit](https://wordpress.org/support/users/dibbit/)
 * Last activity: [15 years, 6 months ago](https://wordpress.org/support/topic/using-setcookie-in-a-plugin/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
