R
Raymundo
Dear,
When a web-broswer sends a GET request, I can get "keywords" or
"param"eters using CGI module, as you know:
$q = new CGI;
$name = $q->param('name');
However, when browser's request includes multi-byte characters, they
can be encoded using UTF-8 or EUC-KR(in Korea, for example) according
to the option in the browswer. ("Send URL in UTF-8" in IE,
"network.standard-url.encode-utf8" in FF, etc.)
At first, I tried to check the value which I got from $q->param() like
this:
$name = $q->param("name");
$name = check_and_convert($name);
....
sub check_and_convert {
# this subroutine guesses the encoding of parameter using
Encode::Guess
# if not UTF-8, it converts the parameter to UTF-8 encoded string and
return it
}
But there are so many parameters and also so many codes using them. I
found that it's almost impossible, or so inconvenient to check
whenever the parameters are fetched.
Second, I tried to "check and convert" $ENV{QUERY_STRING} value before
a CGI object is created:
# convert QUERY_STRING to UTF-8 here
$ENV{QUERY_STRING} = check_and_convert($ENV{QUERY_STRING});
# then create CGI object
$q = new CGI;
# I can get name=XXX and XXX is encoded in UTF-8
$name $q->param("name")
In this case, I think, I don't need to check each parameter in any
other following codes... All the values are now UTF-8 encoded.
As far as I had tested, it looked successful. But I'm not sure that
such approach is good(?) and safe. (I think it's somewhat tricky to
change the environment variable in script..)
Is there any other environment variable or anything else that I should
check before "new CGI;" is called? Can I be sure that I'll not lose
any information when I change QUERY_STRING?
Any advices would be appreciated. I'm soryy I'm not good at English.
Raymundo at South Korea.
When a web-broswer sends a GET request, I can get "keywords" or
"param"eters using CGI module, as you know:
$q = new CGI;
$name = $q->param('name');
However, when browser's request includes multi-byte characters, they
can be encoded using UTF-8 or EUC-KR(in Korea, for example) according
to the option in the browswer. ("Send URL in UTF-8" in IE,
"network.standard-url.encode-utf8" in FF, etc.)
At first, I tried to check the value which I got from $q->param() like
this:
$name = $q->param("name");
$name = check_and_convert($name);
....
sub check_and_convert {
# this subroutine guesses the encoding of parameter using
Encode::Guess
# if not UTF-8, it converts the parameter to UTF-8 encoded string and
return it
}
But there are so many parameters and also so many codes using them. I
found that it's almost impossible, or so inconvenient to check
whenever the parameters are fetched.
Second, I tried to "check and convert" $ENV{QUERY_STRING} value before
a CGI object is created:
# convert QUERY_STRING to UTF-8 here
$ENV{QUERY_STRING} = check_and_convert($ENV{QUERY_STRING});
# then create CGI object
$q = new CGI;
# I can get name=XXX and XXX is encoded in UTF-8
$name $q->param("name")
In this case, I think, I don't need to check each parameter in any
other following codes... All the values are now UTF-8 encoded.
As far as I had tested, it looked successful. But I'm not sure that
such approach is good(?) and safe. (I think it's somewhat tricky to
change the environment variable in script..)
Is there any other environment variable or anything else that I should
check before "new CGI;" is called? Can I be sure that I'll not lose
any information when I change QUERY_STRING?
Any advices would be appreciated. I'm soryy I'm not good at English.
Raymundo at South Korea.