blurredvision Posted December 11, 2008 Share Posted December 11, 2008 I have a cookie that I'm setting like such: setcookie("cookiename", $value, time()+3600*24*5); That works perfectly fine. However, I'm now wanting to create my cookie in a different way, by using a variable to set the name of the cookie. Here's what I'd like to do: setcookie($cookie1, $value, time()+3600*24*5); I cannot get that work. Can you not use a variable to set the cookie name, or is my syntax wrong? Link to comment https://forums.phpfreaks.com/topic/136525-solved-can-i-set-a-cookie-name-with-a-variable/ Share on other sites More sharing options...
flyhoney Posted December 11, 2008 Share Posted December 11, 2008 Yeah you definitely can. Make sure that $cookie1 is a string, and not some other data type. Link to comment https://forums.phpfreaks.com/topic/136525-solved-can-i-set-a-cookie-name-with-a-variable/#findComment-712627 Share on other sites More sharing options...
blurredvision Posted December 11, 2008 Author Share Posted December 11, 2008 It's definitely a string. I've even echoed the variable to make sure it's showing how I want it, and it is. The cookie just doesn't create. Is my syntax correct? Link to comment https://forums.phpfreaks.com/topic/136525-solved-can-i-set-a-cookie-name-with-a-variable/#findComment-712636 Share on other sites More sharing options...
flyhoney Posted December 11, 2008 Share Posted December 11, 2008 Hmm, maybe it is an invalid string? Are there any weird characters in it? Link to comment https://forums.phpfreaks.com/topic/136525-solved-can-i-set-a-cookie-name-with-a-variable/#findComment-712640 Share on other sites More sharing options...
blurredvision Posted December 11, 2008 Author Share Posted December 11, 2008 There is an underscore. Other than that, just letters and a single number. I'm getting part of the string through a function argument, then concatenating a number on to the end. Maybe that's messing with it somehow? Link to comment https://forums.phpfreaks.com/topic/136525-solved-can-i-set-a-cookie-name-with-a-variable/#findComment-712645 Share on other sites More sharing options...
blurredvision Posted December 11, 2008 Author Share Posted December 11, 2008 Figured out what I was doing wrong. I was completely forgetting to pass the $value into the function. What a stupid oversight. I was so stuck on trying to find through google if it was correct syntax or not that I didn't look at other factors. Thanks flyhoney, sorry to waste your time. Link to comment https://forums.phpfreaks.com/topic/136525-solved-can-i-set-a-cookie-name-with-a-variable/#findComment-712653 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.