|
Receiving Non ASCII Characters from Input Forms
Part:
1
2
3
4
5
6
7
(Continued from previous part...)
If you open the dump file, \temp\InputIsoGet.txt, you will see how input strings are URL encoded in
query string, and decoded in $_REQUEST.
------
English=Hello+world%21&Spanish=%A1Hola+mundo%21&
Korean=%26%2350668%3B%26%2348372%3B%26%2349464%3B%26%2350836%3B
+%26%2349464%3B%26%2344228%3B+%21%26%2350668%3B%26%2348372%3B
%26%2349464%3B%26%2350836%3B+%26%2349464%3B%26%2344228%3B+%21&
ChineseUtf8=%26%2320320%3B%26%2322909%3B%26%2319990%3B
%26%2330028%3B%21&ChineseGb2312=%CA%C0%BD%E7%C4%E3%BA%C3%A3%A1
&submit=Submit
------
English = (Hello world!)
Spanish = (¡Hola mundo!)
Korean = (여보세요
세계 !여보세
요 세계 !)
ChineseUtf8 = (你好世界!)
ChineseGb2312 = (ÊÀ½çÄãºÃ£¡)
submit = (Submit)
For example, the Chinese character entered as Unicode was recorded by the browser as "你".
It was then URL encoded into "%26%2320320%3B" when submitted to the server. PHP CGI module recorded
it in $_SERVER['QUERY_STRING'] without any changes. But it was decoded back to "你" when
PHP CGI module copy it to $_REQUEST.
Receiving Non ASCII Characters with POST Method
To test the POST method, I wrote the following script, InputIsoPost.php:
<?php # InputIsoPost.php
# Copyright (c) 2005 by Dr. Herong Yang, http://www.herongyang.com/
#
#- Promoting CGI values to local variables
global $r_English, $r_Spanish, $r_Korean, $r_ChineseUtf8;
global $r_ChineseGb2312;
import_request_variables("GPC","r_");
#- Generating HTML document
print("<html>");
print('<meta http-equiv="Content-Type"'
.' content="text/html; charset=iso-8859-1"/>');
print("<body>\n");
print("<form action=InputIsoPost.php method=post>");
print("English ASCII: <input name=English"
." value='$r_English' size=16><br>\n");
print("Spanish UTF-8: <input name=Spanish"
." value='$r_Spanish' size=16><br>\n");
print("Korean UTF-8: <input name=Korean"
." value='$r_Korean' size=16><br>\n");
print("Chinese UTF-8: <input name=ChineseUtf8"
." value='$r_ChineseUtf8' size=16><br>\n");
print("Chinese GB2312: <input name=ChineseGb2312"
." value='$r_ChineseGb2312' size=16><br>\n");
print("<input type=submit name=submit value=Submit>\n");
print("</form>\n");
#- Outputing input strings back to HTML document
print("<hr>");
print("<pre>");
foreach ($_POST as $k => $v) {
print "$k = ($v)\n";
}
print("</pre>");
print("</body>");
print("</html>");
#- Dumping input strings to a file
$file = fopen("\\temp\\InputIsoPost.txt", 'ab');
$str = "------\n";
fwrite($file, $str, strlen($str));
foreach ($_REQUEST as $k => $v) {
$str = "$k = ($v)\n";
fwrite($file, $str, strlen($str));
}
fclose($file);
?>
If you test this script with Internet Explorer, you will get the same result as InputIsoGet.php.
I was looking for a way to dump the input strings submitted by the POST method. But I could not
find the right function to do this.
(Continued on next part...)
Part:
1
2
3
4
5
6
7
|