Title: Creating a Simple Cookie?
Last modified: August 19, 2016

---

# Creating a Simple Cookie?

 *  [exids](https://wordpress.org/support/users/exids/)
 * (@exids)
 * [17 years, 7 months ago](https://wordpress.org/support/topic/creating-a-simple-cookie/)
 * Good day.
 * This is my first post here, I usually find everythingI am looking for the first
   time through but I am ready to admit defeat on this seemingly simple problem.
 * All I want to do is set a cookie with one value that would be retrieved from 
   teh URL. I want to use simple code like this:
 * $src = $_GET[‘src’];
    setcookie(“source”, $src, time() + 864000, “/”, “.mysite.
   com”);
 * Outside of wordpress using a simple php file, this function poses no problem.
   But as soon as I add this to my function.php template, the variable “$src” is
   no longer inserted into the setcookie function.
 * If I do the following, the value for “src” prints fine on the screen:
 * $src = $_GET[‘src’];
    setcookie(“source”, $src, time() + 864000, “/”, “.mysite.
   com”); echo $src;
 * So, why why is it that the value for “src” will not insert into the setcookie
   function?
 * Strangely enough, when I do something like this, it DOES insert the value for“
   src” without problem:
 * $src = ‘100’;
    setcookie(“source”, $src, time() + 864000, “/”, “.mysite.com”);
 * I know the answer must be simple, but I am absolutley stumped. Could this be 
   a wordpress bug? Thanks a ton in advance for help in resolving this problem.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [exids](https://wordpress.org/support/users/exids/)
 * (@exids)
 * [17 years, 7 months ago](https://wordpress.org/support/topic/creating-a-simple-cookie/#post-888371)
 * By the way, the value for “src” is set in the URL as such:
 * [http://www.mysite.com/index.php?src=googleCPC](http://www.mysite.com/index.php?src=googleCPC)
 *  [drumminlogan](https://wordpress.org/support/users/drumminlogan/)
 * (@drumminlogan)
 * [17 years, 5 months ago](https://wordpress.org/support/topic/creating-a-simple-cookie/#post-888699)
 * Did you ever find an answer? I am trying to do the same thing. Thanks.
 *  [indianabenny](https://wordpress.org/support/users/indianabenny/)
 * (@indianabenny)
 * [16 years, 9 months ago](https://wordpress.org/support/topic/creating-a-simple-cookie/#post-888755)
 * I was going nuts trying to set a basic cookie as well with PHP. Finally tried
   javascript to set the cookie and then I was able to access the info/values via
   PHP. I used the Set_Cookie function located here to do it:
    [http://techpatterns.com/downloads/javascript_cookies.php](http://techpatterns.com/downloads/javascript_cookies.php)
 * I hope WP looks at why cookies are impossible to set within the system. It’s 
   extremely annoying not to be able to set a basic cookie using setcookie (a base
   function in PHP).

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Creating a Simple Cookie?’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 3 participants
 * Last reply from: [indianabenny](https://wordpress.org/support/users/indianabenny/)
 * Last activity: [16 years, 9 months ago](https://wordpress.org/support/topic/creating-a-simple-cookie/#post-888755)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
