set cookie with non-english
| From: | Ahmad Al-Twaijiry | Date: | Mon, 02 Oct 2006 22:15:59 +0000 |
| Subject: | set cookie with non-english | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-242512@lists.php.net to get a copy of this message | ||
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