I'm no PHP expert and I'm trying to set a cookie that contains a referrer code from the URL. For example: www.example.com?promotioncode=google
should set a cookie name promocode, value what ever is after the =
and a 6 month expiry.
I can retrieve the promotioncode using
$_GET['promotioncode']
but I can't seem to insert this into the cookie string. I've tried a few ways:
$id = 'promo';
$value = $_GET['promotioncode'];
$time = time()+60*60*24*180;
setcookie($id, $value, $time);
and
$id = 'promo';
$time = time()+60*60*24*180;
setcookie($id, $_GET['promotioncode'], $time);
but it doesn't work. If I use a word or number as the cookie value then the cookie is set no problem.
What am I missing/doing wrong?
Add a parameter to define the path on the server in which the cookie will be available on :
setcookie($id, $value, $time, '/');
It should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With