Re: set cookie with non-english

From: Date: Wed, 04 Oct 2006 04:18:31 +0000
Subject: Re: set cookie with non-english
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-242596@lists.php.net to get a copy of this message
I already made the application with cookies, it's will be very defaucalt to go and replace cookies with session, is it possible to use cookies & session in the same time ? ( session_start() & setcookie in the same page ?) On 10/3/06, Richard Lynch <ceo@l-i-e.com> wrote:
You'll have to read the cookie spec to confirm, but I'm pretty sure it either specifically disallows other charsets, or at least predates the globalization/i18n efforts... IOW, you can't... You COULD just use session_start() and let them have the PHP cookie, and then store whatever string you want in $_SESSION['UserName'] On Mon, October 2, 2006 5:15 pm, Ahmad Al-Twaijiry wrote: Hi everyone in my PHP code I use the following command to set a cookie with non-english word (UTF-8) : @setcookie ("UserName",$Check[1]); and in my html page I get this cookie using javascript : <script charset="UTF-8" type="text/javascript"> <!-- function getCookie (name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
} var UserName = getCookie("UserName"); document.write(UserName); --> </script> but the result from writing the cookie using javascript is garbage, I don't get the right word !! anyone know how to resolve it ? BTW: * I also tried the php function setrawcookie and I get the same problem * I use <META http-equiv=Content-Type content="text/html; charset=utf-8"> in my page -- Ahmad Fahad AlTwaijiry -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Some people have a "gift" link here. Know what I want? I want you to buy a CD from some starving artist. http://cdbaby.com/browse/from/lynch Yeah, I get a buck. So?
-- Ahmad Fahad AlTwaijiry

« previous php.general (#242596) next »