Page 1 of 5

Php skinning w/ cookies question.

Posted: Sat Feb 19, 2005 8:40 am
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...

Posted: Sat Feb 19, 2005 10:46 am
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.

K

Posted: Sat Feb 19, 2005 11:03 am
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.

Posted: Sat Feb 19, 2005 11:07 am
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..

Um...

Posted: Sat Feb 19, 2005 11:13 am
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).

Posted: Sat Feb 19, 2005 11:28 am
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()

Posted: Sat Feb 19, 2005 11:36 am
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"?

Posted: Sat Feb 19, 2005 11:44 am
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....

Posted: Sat Feb 19, 2005 11:46 am
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

Posted: Sat Feb 19, 2005 11:51 am
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

Posted: Sat Feb 19, 2005 11:54 am
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]

Posted: Sat Feb 19, 2005 11:56 am
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

Posted: Sat Feb 19, 2005 11:57 am
by theda
Ignore the redirect <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>.

Posted: Sat Feb 19, 2005 11:58 am
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;

Posted: Sat Feb 19, 2005 12:04 pm
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.