First off, please bear with the question as I am just starting out with this.
So I have the following running in an index.php:
<?php
if(isset($_COOKIE['language'])) {
if (($_COOKIE['language']) == 'en')
print "<SCRIPT LANGUAGE=\"JavaScript\">window.location=\"URLGOESHERE\"</SCRIPT>";
elseif (($_COOKIE['language']) == 'fr')
print "<SCRIPT LANGUAGE=\"JavaScript\">window.location=\"URLGOESHERE\"</SCRIPT>";
}
else {
print "<SCRIPT LANGUAGE=\"JavaScript\">window.location=\"URL-FOR-COOKIE-SETTING-PAGE\"</SCRIPT>";
}
?>
The “else” statement redirect goes to the page where the user sets their language preference, and once they do so, that page sets a cookie then sends them to the proper version of the site. However, when the user goes back to this main index.php, it cannot seem to find the cookie and skips right to the “else” statement. The redirects used to be used done with PHP using ‘header,’ and it didn’t work then either. I had read elsewhere that that could pose some troubles, so I switched it to try printing Javascript.
The weird thing is that I can find the cookie as soon as it is set, exactly where it should be, with the correct name and variable all present. I’ve done it exactly like the books tell me to (to my knowledge). I’ve tried this both in Firefox and Safari with no luck.
What did I miss?
EDIT: Here’s the script that actually sets the cookie. The parameter is sent from the link via a url encode like this: <a href="setlang.php?lang=en">
<?php
$lang = urlencode($_GET["lang"]);
setcookie("language", $lang, time()+60*60*24*90, ".URL");
switch ($lang) {
case 'en':
header('Location: URLGOESHERE');
break;
case 'fr':
header('Location: URLGOESHERE');
break;
}
?>
Try this code:
I’m uncertain what .URL was supposed to do o.o