xpace Posted June 3, 2007 Share Posted June 3, 2007 Hi guys, I'm very confused and I've searched all over the net but could not find the answer, so hopefully, you'll help. I'm sure there is nothing wrong with my script(at least I think is not) as I went through hundreds of examples and they show the same think. This script is very simple - for now just for testing as I haven't done this before and I'm very close to get it done. Setting language of the page script -> if (!isset($language)) { //this just checks if you have chosen any language (clicked on link with language selection) if (!empty($_COOKIE['set_l'])) { // this one should check if you have been on this site previously - if so, the cookie should be set !!! and this part actually does NOT work even if the cookie is set $lang = $_COOKIE['set_l']; }else{ setcookie("set_l", "en", time()+60*60*24*30, "", "", 1); $lang = "en"; } }else{ $lang = $language; setcookie("set_l", $lang, time()+60*60*24*30, "", "", 1); } thanks guys for any help Quote Link to comment https://forums.phpfreaks.com/topic/54087-checking-if-cookie-is-set-doesnt-work/ Share on other sites More sharing options...
dough boy Posted June 3, 2007 Share Posted June 3, 2007 if (!isset($language)) { //this just checks if you have chosen any language (clicked on link with language selection) }else{ $lang = $language; setcookie("set_l", $lang, time()+60*60*24*30, "", "", 1); } Well...if $language is not set you are then setting a cookie to nothing with the $lang = $language; Then when you check the cookie, the cookie is blank because you filled it with nothing. I am assuming in your else you want it to be 'en'? Quote Link to comment https://forums.phpfreaks.com/topic/54087-checking-if-cookie-is-set-doesnt-work/#findComment-267423 Share on other sites More sharing options...
xpace Posted June 3, 2007 Author Share Posted June 3, 2007 Well...if $language is not set you are then setting a cookie to nothing with the $lang = $language; well... $language does not necessarily need to be set when assuming you are accessing the page first time and if it is not set then code is followed by checking the cookie, which also does not need to be set at the first time = well if it is set then it should be put to variable $lang, (the actual check for cookie if it exists does NOT work for some reason) ---> Then when you check the cookie, the cookie is blank because you filled it with nothing. I am assuming in your else you want it to be 'en'? ---> if it is not, then it should be created with "en". then if the $language is set then variable $lang will be set with value from $language -> $lang = $language; and then it will be put into cookie -> setcookie("set_l", $lang, time()+60*60*24*30, "", "", 1); thank you anyway Quote Link to comment https://forums.phpfreaks.com/topic/54087-checking-if-cookie-is-set-doesnt-work/#findComment-267437 Share on other sites More sharing options...
dsaba Posted June 3, 2007 Share Posted June 3, 2007 you can only check if a cookie has been set isset($_COOKIE['whatever']) when the page has been reloaded, if you set the cookie on that same pageload try it Quote Link to comment https://forums.phpfreaks.com/topic/54087-checking-if-cookie-is-set-doesnt-work/#findComment-267440 Share on other sites More sharing options...
xpace Posted June 4, 2007 Author Share Posted June 4, 2007 thank you guys, I have found the problem myself > the only problem was in setting up cookie last parameter 0 or 1 for secure connection setcookie("set_l", $lang, time()+60*60*24*30, "", "", 1); I had 1 for secure connection and I don't use that connection, changed to 0 and it works like charm thank you. Quote Link to comment https://forums.phpfreaks.com/topic/54087-checking-if-cookie-is-set-doesnt-work/#findComment-267897 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.