Jump to content

Recommended Posts

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

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/54087-checking-if-cookie-is-set-doesnt-work/
Share on other sites

 

        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'?

 

 

 

 

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  ;)

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.