How to change charset=ISO-8859-1 to charset=UTF8? Rocky 9.1 server
Hi ! Everyone, I am back here to ask environmental issue.
When I ran the following CGI.pm testing script before placing at /var/www/cgi-bin, but it is still at /home/mkido/bin. Perl script ran successfully at the Terminal, and replied back the OUTPUT below there.
Perl Script, check.pl
#!/usr/bin/env perl
use strict;
use warnings;
use CGI;
my $q = CGI->new;
print $q->header();
print "OK";
===================
OUTPUT
mkido@localhost$check.pl [Enter to run it.]
Content-Type: text/html; charset=ISO-8859-1
OK
mkido@localhost$
This output result evoked my recognition. Is this Rocky 9.1 Web Server running to provide charset=ISO-8859-1 ?? I want to set all replies from the Server to charset=UTF-8. The httpd.conf is already set to charset=UTF-8. Is there any other setting adjustment somewhere in environmental configuration on my server to change from charset=ISO-8859-1 to charset=UTF-8 ?? Thanks, thanks.
I would assume that the Perl CGI module is so old it defaults to latin-1. A quick glance at the docs confirms this:
https://metacpan.org/dist/CGI/view/lib/CGI.pod#Creating-a-standard-http-header
"The -charset parameter can be used to control the character set sent to the browser. If not provided, defaults to ISO-8859-1."
So you'll need to tell CGI.pm explicitly to use utf8 via $cgi->header(-charset => 'utf-8') AND make sure the content is correctly encoded.
That being said, I would not use plain CGI.pm but look into Plack/PSGI instead (which has a CGI compat mode).
Thank you, domm, I can manage to change $cgi->header(=>'utf-8'). It worked.
By the way, I have a tiny question related with character encoding. To clearly present my question, I want to post screenshot (png or jpg) here. May I use graphics file attachment here?
Sorry there is a typo.
$cgi->header(-character=>'utf-8'). It worked.
Yes, at least there are multiple posts using images etc