jtorral Posted May 22, 2010 Share Posted May 22, 2010 Normally, I would check for a cookie something like this $_COOKIE['cookie_name'] But how can I do this ... $cn = "cookie_name"; $_COOKIE['$cn']; I can't get it to work. Is there a special way of assigning a variable to a global predefined? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/202611-putting-variables-inside-predefined-variables-possible/ Share on other sites More sharing options...
Daniel0 Posted May 22, 2010 Share Posted May 22, 2010 Do like $_COOKIE[$cn] without the quotes around the variable name. Quote Link to comment https://forums.phpfreaks.com/topic/202611-putting-variables-inside-predefined-variables-possible/#findComment-1062055 Share on other sites More sharing options...
jtorral Posted May 22, 2010 Author Share Posted May 22, 2010 i tried that and it does not work Quote Link to comment https://forums.phpfreaks.com/topic/202611-putting-variables-inside-predefined-variables-possible/#findComment-1062060 Share on other sites More sharing options...
Daniel0 Posted May 22, 2010 Share Posted May 22, 2010 Okay... How did you try it, and how does it "not work"? Help me help you. It's not like I can see what's going on on your computer, so vague statements like "it does not work" are entirely useless. Quote Link to comment https://forums.phpfreaks.com/topic/202611-putting-variables-inside-predefined-variables-possible/#findComment-1062061 Share on other sites More sharing options...
jtorral Posted May 22, 2010 Author Share Posted May 22, 2010 i have javascript that sets a cookie when I click on a link. I then call the function below to check the value of the cookie. I am trying to use variable $div because I have 20 cookies withe the name xxx_div1 through xxx_div20 therefor I try to create the cookie name in the call so ai can minimize code. If i take the function below and replace $divcn with the actual cookie name it works as expected. If I use the variable, it always goes to the else. function checkdivsettings($div) { $divcn = "xxx_" . $div; if(isset($_COOKIE[$divcn])) { $div = $_COOKIE[$divcn]; } else { $div = "block"; } return $div; } Quote Link to comment https://forums.phpfreaks.com/topic/202611-putting-variables-inside-predefined-variables-possible/#findComment-1062067 Share on other sites More sharing options...
jtorral Posted May 23, 2010 Author Share Posted May 23, 2010 figured it out! The proverbial wrong spelling! Quote Link to comment https://forums.phpfreaks.com/topic/202611-putting-variables-inside-predefined-variables-possible/#findComment-1062085 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.