Re: set cookie with non-english

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux