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? Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.