开发者

Encode cgi scripts UTF-8 or not?

开发者 https://www.devze.com 2023-04-05 06:43 出处:网络
I have been encoding all my website to UTF-8 after reading about the basics of encoding and character sets and all that stuff.

I have been encoding all my website to UTF-8 after reading about the basics of encoding and character sets and all that stuff. I have just uploaded a cgi script UTF-8 encoded. It reads data from an HTML form (also UTF-8) and I keep getting a 500 error. I have even made an script just to say "OK" and it doesn't work. I mean, no reading from a form, no reading nothing, just printing a line.

#!/usr/bin/perl
use utf8;
BEGIN {
    $| = 1;
    open (STDERR, ">开发者_StackOverflow中文版&STDOUT");
    print qq~Content-type: text/html\n\n~;
}
print "ok";

I have moved the use "utf8;" below the BEGIN block and none is working. So, the 500 error says the script is not being read, as it if hadn't 755 permissions (it has).

So, my question is not about reading UTF8 data, but about running UTF8 encoded perl script.

Should I keep my scripts ANSI encoded (and work around reading the utf8 data from HTML forms)?

I have Perl 5.8 running on Apache on Linux. And... if I encode the script to Ansi, it works well (except for the reading of UTF-8 characters, but that's another story)


use utf8 means only that your Perl source code is in UTF-8. It has nothing to do with whether the script can process UTF-8 data from a form.

If your script stops working when you add the use utf8; line, then I see two possible problems:

  1. There's something wrong with your Perl installation, so you get an error when it tries to load utf8.pm, or (more likely)

  2. Your editor inserts a BOM when you save a file as UTF-8. The BOM interferes with the #! processing, so your script can't run.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号