是否将 cgi 脚本编码为 UTF-8?
在阅读了编码和字符集的基础知识以及所有这些内容后,我已经将我的所有网站编码为 UTF-8。 我刚刚上传了一个 UTF-8 编码的 cgi 脚本。它从 HTML 表单(也是 UTF-8)读取数据,但我不断收到 500 错误。 我什至制作了一个脚本只是为了说“好吧”,但它不起作用。我的意思是,不读取表格,不读取任何内容,只打印一行。
#!/usr/bin/perl
use utf8;
BEGIN {
$| = 1;
open (STDERR, ">&STDOUT");
print qq~Content-type: text/html\n\n~;
}
print "ok";
我已经移动了使用“utf8;”在 BEGIN 块下面,没有一个起作用。因此,500 错误表示脚本未被读取,因为它没有 755 权限(它有)。
所以,我的问题不是关于读取 UTF8 数据,而是关于运行 UTF8 编码的 perl 脚本。
我应该让我的脚本保持 ANSI 编码(并解决从 HTML 表单读取 utf8 数据的问题)吗?
我在 Linux 上的 Apache 上运行 Perl 5.8。而且...如果我将脚本编码为 Ansi,它会很好地工作(除了读取 UTF-8 字符,但那是另一个故事了)
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, ">&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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
use utf8
仅表示您的 Perl 源代码采用 UTF-8。它与脚本是否可以处理表单中的 UTF-8 数据无关。如果您的脚本在添加
use utf8;
行时停止工作,那么我会看到两个可能的问题:您的 Perl 安装有问题,因此当它尝试加载 < code>utf8.pm,或(更有可能)
你的编辑当您将文件另存为 UTF-8 时,会插入 BOM。 BOM 会干扰
#!
处理,因此您的脚本无法运行。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:There's something wrong with your Perl installation, so you get an error when it tries to load
utf8.pm
, or (more likely)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.