Php skinning w/ cookies question.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

theda
Forum Contributor
Posts: 332
Joined: Sat Feb 19, 2005 8:35 am
Location: USA

Php skinning w/ cookies question.

Post by theda »

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...
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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.
theda
Forum Contributor
Posts: 332
Joined: Sat Feb 19, 2005 8:35 am
Location: USA

K

Post by theda »

I'll try that once. Next thing I want to know is how I can use the cookie to change the "skin," while using the same cookie.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what don't you understand about setting the cookie information? It's quite straight forward unless you are trying to do something out of the ordinary..
theda
Forum Contributor
Posts: 332
Joined: Sat Feb 19, 2005 8:35 am
Location: USA

Um...

Post by theda »

I know how to set a cookie, but how do I use the isset function to open it and figure out whether the cookie says "en" or "de" (for english and deutsch/german).
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

isset() doesn't open a cookie. All it does is check if the variable named exists, that's it.

$_COOKIE['cookiename'] will contain whatever "value" you set with setcookie()
theda
Forum Contributor
Posts: 332
Joined: Sat Feb 19, 2005 8:35 am
Location: USA

Post by theda »

Edit: I just understood what you said.

Now on the page that I am trying to use to "set" the cookie, how do I use the isset function to either set a cookie for "de" or "en"?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

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....
theda
Forum Contributor
Posts: 332
Joined: Sat Feb 19, 2005 8:35 am
Location: USA

Post by theda »

What Im asking is how do I set a cookie based on an isset function? If blah.com/index.php?set=end then it sets a cookie to en
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Use conditions

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
    }
}
Just standard condition checking
Last edited by Chris Corbyn on Sat Feb 19, 2005 11:54 am, edited 1 time in total.
theda
Forum Contributor
Posts: 332
Joined: Sat Feb 19, 2005 8:35 am
Location: USA

Post by theda »

so..

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 the

Code: Select all

tags are offline[/color]
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

That doesn't look like anything to do with skins... are you just redirecting to a different site?

Why would you check if a cookie has been set then set it again?

See my last post.

BTW: Read up on header('location: .....') for redirecting
theda
Forum Contributor
Posts: 332
Joined: Sat Feb 19, 2005 8:35 am
Location: USA

Post by theda »

Ignore the redirect <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

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.

Code: Select all

$var1 = 'test';
$var2 = 'test2';

if (isset($var1)) &#123; //Check the variable even exists
   echo $var1; //In this script this will be the output
&#125; else &#123;
    echo 'var1 is not set';
&#125;

if (isset($var99)) &#123;
   echo $var99; //Doesn't exist so will be ignored
&#125; else &#123;
   echo 'var99 does not exist'; //This is the output here
&#125;
theda
Forum Contributor
Posts: 332
Joined: Sat Feb 19, 2005 8:35 am
Location: USA

Post by theda »

I am trying to use the ?SET=SOMETHING isset part to either set an "en" cookie or set an "de" cookie. Why don't you start paying attention.
Post Reply