/    Sign up×
Community /Pin to ProfileBookmark

Tiresome question, sanitizing user HTML input

I hate to be asking this question, 1. because it’s a typical newb question that probably gets asked a lot, and 2. because I’ve done some tuts on this but now can’t seem to find files i’d saved to refer to.

but anyway, i’m building a simple cms. there are some text fields for user input. this input gets displayed on a web page and the user needs to be able to enter in simple HTML tags like <span class=’whatever’>, <b>, <p>…. etc. etc..

i know i need to sanitize the input. can someone suggest what all functions i should use?, like addslashes(), (going into the D?, removeslashes(), (going back out onto the page), htmlspecialchars()……should i use..?. should i use filter_var(‘copy’,FILTER_SANITIZE_STRING )…?

or can someone point me in the right dir. for some good tuts on this topic?, big thanks

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@BelrickJul 05.2012 — Good question

I just use add slashes for ajax data and mysql_real_escape_string for forms used for logging in.
Copy linkTweet thisAlerts:
@NogDogJul 06.2012 — My recommendation would be to use one of the WYSIWYG plug-ins out there (such as TinyMCE), which will both provide a nice interface to the users while handling all the nuts and bolts for you.

PS: There is generally no reason to be using addslashes() or stripslashes() anywhere. You should be using the escaping mechanism specific to the DBMS extension being used (or better yet, using prepared statements and bound parameter), and there should never be a need to remove slashes on data retrieved from the DB, since [i]the escaping slashes never actually get into the database[/i] (they just tell the SQL parser which characters to treat literally rather than as special characters).
Copy linkTweet thisAlerts:
@toptomatoauthorJul 07.2012 — belated thanks a lot guys
×

Success!

Help @toptomato spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...