Specifying the database encoding in the site scripts when using cPanel hosting and control panel

Guidance on how to change the encoding of the site through the configuration file .htaccess

By default, the global MySQL encoding on shared hosting servers is set "cp1252 West European (latin1) ", this is a feature of the control panel cPanel.

To specify the encoding of your site for displaying it in the browser, go to "Files → File Manager "

file

Let's go to "public_html " folder.

file

By default, the ".htaccess " file is hidden. So let's click on the "Settings" button and put a tick mark next to "Show hidden files (dotfiles) ".

file

Next, select our .htaccess and click "Edit ".

file

In the window that will appear let's click "Disable encoding check " and click "Edit ".

file

Let's specify the following values at the beginning of the file:

  • If we want to use UTF-8 encoding
AddDefaultCharset UTF-8 
  • If we want to use Windows-1251 encoding
AddDefaultCharset WINDOWS-1251 

file

Then you can click "Save changes ".

Now go to our site and clear the browser cache by pressing "Ctrl + F5" or "Ctrl + R ". The encoding should change.


It is also worth checking which encoding is used in your database. To do this let's go into the database management utility "Databases → phpMyAdmin "

file

Open the desired database by clicking on its name on the left, and go to "Operations "

In the Compare field, set the same encoding as used on the site.

file

file

Now clear browser cache by pressing "Ctrl + F5" or "Ctrl + R " and check how the site displays.


Also you need to check the encoding when requesting data in your site scripts and specify the required encoding For example for UTF-8.

mysql_query ("set_client='utf8'");
`` mysql_query ("set character_set_results='utf8'");
mysql_query ("set collation_connection='utf8_general_ci'");
mysql_query ("SET NAMES utf8");
Need help?Our engineers will help you free of charge with any question in minutesContact us