Cookies are quite easy to use and shouldnt take that long to learn how to manipulate.
Basically a cookie holds a value which can then be read using the $_COOKIE super global.
so the cookie syntax is:
setcookie ($name ,$value, $expire, $path, $domain, $secure, $httponly)
You dont need to use all the arguments though:
PHP Code:
setcookie('myCookieName', 'myCookieValue');
Would do to set the basic cookie.
PHP Code:
$language = $_GET['language']; // eg fr or gb
setcookie('language_cookie', $language);
#print_r($_COOKIE['language_cookie']);
if(isset($_COOKIE['language_cookie'])) {
echo 'use language:'. $_COOKIE['language_cookie'];
} else {
echo 'No Cookie Available';
}
Now the thing with cookies is that they are only available AFTER the page that has set them has either been refreshed or the user has moved on to a different page. To use the language selected you can:
PHP Code:
$language = $_GET['language'];
$_SESSION['language_temp'] = $language;
setcookie('language_cookie', $language);
#print_r($_COOKIE['language_cookie']);
if(isset($_COOKIE['language_cookie'])) {
unset($_SESSION['language_temp']);
echo 'use language:'. $_COOKIE['language_cookie'];
} else {
echo 'No Cookie Available but I can use the session var, so:'. $_SESSION['language_temp'];
}
Hope that helps
Bookmarks