I am writing my first guestbook on PHP with authentication. How to assign a charset to UTF-8
I do this at the beginning of the code.
Code:
<?php
$_SERVER['HTTP_ACCEPT_CHARSET'] = 'utf-8;q=0.5';
$passwd = array('user1' => 'password1');
if (!isset($_SERVER['PHP_AUTH_USER']) ||
!isset($_SERVER['PHP_AUTH_PW']) ||
$passwd[$_SERVER['PHP_AUTH_USER']] != $_SERVER['PHP_AUTH_PW']) {
header('WWW-Authenticate: Basic realm="feedback" ');
header('HTTP/1.0 401 Unauthorized');
$authenticated = false;
}
else {
header('charset=utf-8');
$authenticated = true;
session_start();
?>
... rest of the code and html body of the guestbook
But the browser does not get switched to UTF-8 automatically, I must do it manually.
What is wrong with this piece of code?
Thanks.