Php skinning w/ cookies question.
Moderator: General Moderators
Php skinning w/ cookies question.
I'm looking to "skin" my website so that I can have my website in different languages (mainly, English and German). I'm not doing this website for a professional reason, just personal knowledge.
My question is how can I use the setcookie() function to set a cookie that I can later open up with isset() so that I can set a cookie that tells the script I use what language to use (and then later open that cookie up so that my script KNOWS what to do?)
The only major problem is that my host doesn't support $_COOKIE["string..."]
I was once able to substitute the previous line for $string. But I don't understand how to use it anymore. It was a while back that I originally learned this and forgot it now...
My question is how can I use the setcookie() function to set a cookie that I can later open up with isset() so that I can set a cookie that tells the script I use what language to use (and then later open that cookie up so that my script KNOWS what to do?)
The only major problem is that my host doesn't support $_COOKIE["string..."]
I was once able to substitute the previous line for $string. But I don't understand how to use it anymore. It was a while back that I originally learned this and forgot it now...
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
you just call setcookie() with the proper information.
If $_COOKIE doesn't exist, $HTTP_COOKIE_VARS (or whatever the old name is) may.. depends on your version of php. It does appear that your host has register_globals on, which typically means an old version of php, or a not so smart hosting of a newer php.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
What are you on about? Do you even know how to use cookies? You just need to set a cookie with a value, say language=de and then if the cookie is set you just read back what language has been set in the cookie.
If you get that far your next (easy) hurdle is to make a condition to decide which skin to use based on the value of the cookie.
Maybe you should read up a bit on using cookies, setting cookies and deleting cookies....
If you get that far your next (easy) hurdle is to make a condition to decide which skin to use based on the value of the cookie.
Maybe you should read up a bit on using cookies, setting cookies and deleting cookies....
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Use conditions
if, elseif, else
Just standard condition checking
if, elseif, else
Code: Select all
if (isset($_COOKIEї'cookiename'])) {
if ($_COOKIEї'cookiename'] == 'en') {
//Use the english skin
} elseif ($_COOKIEї'cookiename'] == 'de') {
//Use german cookie
} else {
//Use whatever
}
}
Last edited by Chris Corbyn on Sat Feb 19, 2005 11:54 am, edited 1 time in total.
so..
feyd | please use
Code: Select all
if (isset($set == "en")) {
setcookie("ver",$en,time()+3600);
print "<meta http-equiv=/"Refresh/" content=/"0;url=http://dumbass.ionichost.com/">";
}
elseif (isset($set == "de")) {
setcookie("ver",$de,time()+3600);
print "<meta http-equiv=/"Refresh/" content=/"0;url=http://dumbass.ionichost.com/">";
}
else {
setcookie("ver",$en,time()+3600); //If there is nothing being set, then it'll auto set to en
}feyd | please use
Code: Select all
tags while theCode: Select all
tags are offline[/color]- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
What are you stuck on? Reading the cookie information and deciding what to do with it, or actually setting the cookie in the first place because all your code does (if you had written it properly) is sets a cookie that has already been set.....
You don't seem to know what isset is supposed to do.
You don't seem to know what isset is supposed to do.
Code: Select all
$var1 = 'test';
$var2 = 'test2';
if (isset($var1)) { //Check the variable even exists
echo $var1; //In this script this will be the output
} else {
echo 'var1 is not set';
}
if (isset($var99)) {
echo $var99; //Doesn't exist so will be ignored
} else {
echo 'var99 does not exist'; //This is the output here
}