note 99185 added to function.htmlspecialchars
| From: | Anonymous at osu1 dot php dot net | Date: | Sun, 01 Aug 2010 20:48:16 +0000 |
| Subject: | note 99185 added to function.htmlspecialchars | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-171322@lists.php.net to get a copy of this message | ||
This may seem obvious, but if you want to output arbitrary (i.e. user-input) data as an attribute
inside an HTML tag (such as the INPUT tags on a FORM), be aware of whether you are using ENT_QUOTES
or ENT_COMPAT. If you're using ENT_COMPAT, the attribute must be wrapped in double-quotes, as
single-quotes will not be encoded and the user will be able to inject arbitrary HTML attributes
(including javascript behavior) inside the tag, even though they will not be able to inject
arbitrary HTML tags.
Also, if you want to allow users to input HTML attributes without them being double-encoded on
display, there are two ways to accomplish this:
1 - Run their input through htmlentities_decode() followed by htmlspecialchars().
2 - Call htmlspecialchars() with $double_encode=false.
There is one functional difference between these two methods: If you want to perform any
search-replace on a user's input (such as word censoring in a message-board application), the
second method will allow users to circumvent it by HTML-encoding their input, whereas the first will
not.
----
Server IP: 64.71.164.2
Probable Submitter: 71.54.198.140
----
Manual Page -- http://www.php.net/manual/en/function.htmlspecialchars.php
Edit -- https://master.php.net/note/edit/99185
Del: integrated -- https://master.php.net/note/delete/99185/integrated
Del: useless -- https://master.php.net/note/delete/99185/useless
Del: bad code -- https://master.php.net/note/delete/99185/bad+code
Del: spam -- https://master.php.net/note/delete/99185/spam
Del: non-english -- https://master.php.net/note/delete/99185/non-english
Del: in docs -- https://master.php.net/note/delete/99185/in+docs
Del: other reasons-- https://master.php.net/note/delete/99185
Reject -- https://master.php.net/note/reject/99185
Search -- https://master.php.net/manage/user-notes.php