note 78833 added to function.setcookie

From: Date: Tue, 30 Oct 2007 08:29:35 +0000
Subject: note 78833 added to function.setcookie
Groups: php.notes 
Request: Send a blank email to php-notes+get-131824@lists.php.net to get a copy of this message
Problem with setcookie() and UTF-8 recognizing by browser: - If you want to use UTF-8 characters in your php file, some editors insert special bytes in the very beginning of the file. This prevents setcookie() from working, because these special bytes are sent to the browser BEFORE the header, and you get "Header already sent" error; - If you delete these bytes (with a hex editor), setcookie() will work fine, but the browser will STOP recognizing UTF-8 encoding automatically! The user will need to set the encoding to UTF-8 manually to see your page correctly. Here's how to get out of this: Instead of: <? setcookie("aaa", "bbb"); ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> Write this: <? header("Content-Type: text/html; charset=utf-8"); setcookie("aaa", "bbb"); ?> <html> <head> ... (make sure you have no special bytes before "<?") ---- Server IP: 217.174.196.197 Probable Submitter: 194.2.176.227 ---- Manual Page -- http://www.php.net/manual/en/function.setcookie.php Edit -- https://master.php.net/note/edit/78833 Del: integrated -- https://master.php.net/note/delete/78833/integrated Del: useless -- https://master.php.net/note/delete/78833/useless Del: bad code -- https://master.php.net/note/delete/78833/bad+code Del: spam -- https://master.php.net/note/delete/78833/spam Del: non-english -- https://master.php.net/note/delete/78833/non-english Del: in docs -- https://master.php.net/note/delete/78833/in+docs Del: other reasons-- https://master.php.net/note/delete/78833 Reject -- https://master.php.net/note/reject/78833 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#131824) next »