Web Developer (Drupal)
Aquent
US-CA-San Rafael

Justtechjobs.com Post A Job | Post A Resume

Displaying Formatted User Input
This document describes how to display safely formatted output from user input. We will discuss the dangers of displaying unfiltered output and then provide a safe means of displaying formatted output. Download ying20000718.zip and extract it into your web documents directory.
Dangers of Unfiltered Output
If you just took the user's input and displayed it as is, you may break your webpage. For example, someone can maliciously embed javascript in their comment like:
This is my comment. 
<script language="javascript: 
alert('Do something bad here!')">.
Even if the user had no bad intentions, they may accidentally put some HTML that breaks your site layout. For example if you displayed the user's input in a table and they included an improperly nested </table> tag, your page appears broken.
Displaying Plain Text Only
The easiest solution would be to only display plain text in the comment. Using the htmlspecialchars() function, you convert all the special characters into HTML entites. For example <b> would become &lt;b&gt;, turning it into text instead of an HTML tag. This guarantees that there are no HTML markups in the comment that would produce unwanted output.
This is an okay solution if your guests don't mind entering in only plain text, but it would be a lot better if you gave them some formatting abilities.
[ Next Page ]


Comments:
±â³×½ººÏ µµÀü, 100¹è »¡¶óÁö°í ½¬¿öÁø ¿µ¾î¿ø¸® ÀÌÈÆ±â11/15/05 22:34
RE: Unclosed Tags?Filipe02/21/05 19:50
½Å.¿ë.ºÒ.·®ÀÚ°¡ ¾Ë¾Æ¾ßÇÒ Á¤.º¸/´ë°ø°³ÇÏÁö¿¬12/28/04 02:21
Ä«/µå/µ¹·Á¸·±â·Î/¸Á°¡Áö½ÅºÐ/²À º¸¼¼¿ä!ÀÌÇýÁø12/07/04 06:18
Ä«,µå,¿¬,ü,ÀÚ/¿¹.Á¤.ÀÚ ´ë,Ãâ 100-1000¸¸¿øÀÌ´ÙÇö12/05/04 06:47
´ë'Ãâ'°Å'Àý'½Ã'100%µÇ'°Ô'ÇÏ'´Â'¹æ'¹ýÇѰæ¿í12/04/04 21:45
½Å.¿ë.ºÒ.·®.ÀÚ/´çÀÏ500/´ë.Ãâ.ºñ.¹ýÀÌÈñÁø12/02/04 09:27
½Å.¿ë.ºÒ.·®/Ä«.µå.¿¬.ü/´ë.Ãâ/È¥ÀÚ/ÇØ.°áÇÏ´Â/¹æ.¹ý±èÇö¼­11/27/04 23:55
½Å.¿ë.ºÒ.·®.ÀÚ/´çÀÏ500/´ë.Ãâ.ºñ.¹ýÀÌÈñÁø11/27/04 12:32
´ë'Ãâ'°Å'Àý'½Ã'100%µÇ'°Ô'ÇÏ'´Â'¹æ'¹ýÇѰæ¹Î11/23/04 11:11
½Å.¿ëºÒ.·®ÀÚ°¡ ¾Ë¾Æ¾ßÇÒ Á¤.º¸ ´ë.°ø.°³ ÀÌ´ÙÁø11/22/04 03:08
Ä«/µå/µ¹·Á¸·±â·Î/¸Á°¡Áö½ÅºÐ/²À º¸¼¼¿ä!ÀÌÁ¤¿¬11/18/04 13:03
5.ºÐ.¸¸¿¡ 4.0¸¸.¿ø ¹«,ÀÌ.ÀÚ·Î ºô.¸®±âÁö¿µÈñ11/17/04 12:43
Ä«.µå.±ø.¾È.ÇÏ.°í.µ·.¸¸.µé.¾î.¾².´Â.ºñ.¹ýÀÌÈñÁø11/15/04 10:25
RE: off topicAmo10/29/03 19:40
Thanks Yingbacaribaro08/05/03 12:50
multiple page forms / formatting outputJose candelaria10/24/02 22:29
Use real HTML in input, but safelyBastiaan09/22/02 04:19
Database Driven Version in PHPRobert Taylor (Manix)08/20/02 16:15
RE: this is exactly what i wanted to knowTony Reid07/21/02 16:35
RE: saving user input in databasecraig jardine05/04/02 08:28
YOU ROCK!Ernest Correale05/01/02 10:54
SQL Error 1064 when $output contains a 'James Wyld04/25/02 22:12
off topicjeff03/12/02 23:50
replace, but not between <t>hes</e>Tsunami01/21/02 16:00
this is great!Leah Yates12/20/01 15:36
RE: parenthesisRockMonkey10/28/01 20:47
parenthesisandrew b08/27/01 15:14
saving user input in databaserishabh gupta08/16/01 10:15
Easy WayDarren Valentine07/27/01 05:26
RE: JavaScript Auto Formatting?Richard06/27/01 06:25
html<->pseudojuozas salna05/07/01 07:14
General script for replacing pseudo-markupJakob Persson04/27/01 09:13
RE: Generating linksVargo03/17/01 08:59
Generating linksLeo Miyagi02/19/01 10:23
php to call data neededlei02/11/01 01:07
UBB code translation functionZulu12/01/00 05:52
JavaScript Auto Formatting?Frank11/27/00 06:02
RE: yeah , but i'm slow like turtleOliwier09/30/00 18:20
RE: mouseovers in linksYing Zhang09/05/00 00:40
mouseovers in linksJoe Sheble08/30/00 18:30
Editing formated codeJ. Kobinski08/06/00 15:17
RE: Unclosed Tags?Cédric CHERCHI08/01/00 12:01
RE: yeah , but i'm slow like turtleSean Pecor07/25/00 20:05
RE: yeah , but i'm slow like turtleAdrian Kubala07/25/00 12:15
RE: str_tagsYing Zhang07/24/00 05:05
RE: Unclosed Tags?Keita Ito07/23/00 18:01
RE: instead of custom markup languages...Keita Ito07/23/00 17:56
RE: instead of custom markup languages...Keita Ito07/23/00 17:53
RE: instead of custom markup languages...Ben Munoz07/21/00 14:01
instead of custom markup languages...Ben Munoz07/21/00 13:56
Unclosed Tags?Brian Mertens07/21/00 00:44
yeah , but i'm slow like turtlephilip olson07/21/00 00:33
SimilarMike Hall07/20/00 05:11
RE: An additionVincent Vollers07/20/00 04:52
RE: An additionDoug MacDougall07/20/00 01:18
Just use HTML.. life is complicated enoughDoug MacDougall07/20/00 01:06
RE: str_tagsSteve Yelvington07/19/00 19:45
An additionVincent Vollers07/19/00 13:18
str_tagsMatt07/19/00 11:45
this is exactly what i wanted to knowphilip olson07/19/00 00:17
 

If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly.

Add A Comment:

Name:

Email:

Subject:

Message:

To reduce spam posts, messages are now manually approved

You are not [logged in]. That means your account will not get credit for this post.