To save the cookie as a link, try the following.
Code:
<?php
$homepage = 'http://'.$_SERVER["HTTP_HOST"].'/';
if ($_REQUEST['act'] == "setLang") {
//check to see if the form has been submitted!
if ($_REQUEST['lang'] == "") {
header('Location: '.$_SERVER["PHP_SELF"]);
//if language selection is empty, redirect to form!
}
else {
//if language was selected, save it in a cookie, then redirect to appropriate page!
$lang = $_REQUEST['lang'];
setcookie("language, $lang, time()+3600);
header('Location: '.$homepage.$lang);
}
}
else {
//if form has not been submitted
if (@$_COOKIE['language'] != "") {
/* check to see if language cookie is empty. If not, redirect to appropriate page. */
header('Location: '.$homepage.$_COOKIE["language"]);
}
else {
//if cookie is empty, display form
?>
<html>
<head>
<title>Language Cookie Test</title>
</head>
<body>
<a href="?act=setLang&lang=en">English</a>
<a href="?act=setLang&lang=sp">Spanish</a>
<a href="?act=setLang&lang=ru">Russian</a>
</body>
</html>
<?php
}
}
?>
Hope this helps.
Bookmarks