I am setting up an affiliate link area for my site and need to be able to store a URL query string into a cookie that expires in a 7 days.
Users will click on a link like: http://examplesite.com?afil=randomvalue.
I want to pull the key 'afil' and the value 'randomvalue' and put it in a cookie.
This will be used later down the road in another area of the site and I can't keep it in the URL.
I found this post: Set a Cookie based on url Parameter
But it doesn't seem to do what I want or set an expiration date. I am not sure if it is best to use php or javascript for this but I was planing on using php to pull the data later.
UPDATE:
I added this code to my dev site here: http://inventivewebdesign.com/dev/about?afil=great
<?php
$value=$_GET['afil']; //the value from the url
setcookie("afilCookie", $value, strtotime( '+7 days' )); /* expire in 7 days */
echo "Cookie = " . $value;
?>
As you can see, it does display the cookie value (I added it right at the end of my header.php file which puts it in the body). For some reason it doesn't add it to my cookies when I view them.
Also, does this need to be made conditional for if there is no afil value?