Home >Backend Development >PHP Tutorial >Solving the problem of garbled referrers_PHP tutorial
The referrers system can display backlinks very well. Currently, the latest source (referer) statistics displayed on many sites use Stephen's referrer statistics system. What we are going to discuss today is not its installation problem, but its character set garbled problem
This software has a character set problem. I think everyone will encounter this problem, because my blog is UTF- 8 characters, and many domestic websites with backlinks are GB2312, so when statistics are calculated, GB2312 shows garbled characters. It is very ugly, so it is necessary to unify the character set through technical means.
With the help of hedong, I finally solved this problem. In fact, icov and Text-Iconv-1.2 are used to convert GB2312 into UTF-8. The following are the specific steps:
1. Check whether the iconv software package is installed
iconv -V
If iconv does not exist, you need to install the glibc-common*.rpm package.
2. Download the Text::Iconv module and install it
wget http://search.cpan.org/CPAN/authors/id/M/MP/MPIOTR/Text-Iconv-1.2.tar .gz
tar zxvf Text-Iconv-1.2.tar.gz
cd Text-Iconv-1.2
perl Makefile.PL
make
make test
make install
3. Configure referrers.cgi (not many people are using it now) file
in use cgi (not many people are using it now) qw(: cgi(not many people use it now)-lib); add the following statement;
use Text::Iconv;
my $converter = Text::Iconv->new ("GB2312", "UTF-8");
In the # Print out the information section, add the following similar statement
if (index($durl,"baidu.com")> -1 ||index($durl,"msnfans.com")>-1 ||index($durl,"mybh.net")>-1 ||index($durl,"hed
ong. 3322.org")>-1) {
$dtit=$converter->convert($dtit);
}
In the future, websites that need to be converted will be manually added. .
If you are transmitting UTF-8 to GB2312, it is similar
Thanks again hedong for your help:)