/    Sign up×
Community /Pin to ProfileBookmark

Securing php forum

I’m setting up a comments system on a site, with the comments stored in a mysql database. To prevent sql-injection, I run mysql_real_escape_string() on ingoing data. This should be enough to protect the database (tell me if otherwise), but I’d like to prevent people from posting Javascript and other malicious html. Basically, I’d like the comments to be bbcode and text only, using this bbcode parser:
[url]http://il.php.net/manual/en/function…lace.php#69398[/url]

How can I strip the remaining html, javascript, and whatnot from the posts? If somebody has already invented this wheel, then I’d rather not risk a security breach by trying to reinvent it myself.

Dotan Cohen
[url]http://song-lirics.com[/url]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@intriviousNov 07.2006 — Could you use htmlentities()?
Copy linkTweet thisAlerts:
@dotancohenauthorNov 08.2006 — That seems to be the ticket, thanks. It doesn't remove the bad code, but it does prevent it from destroying the page.
Copy linkTweet thisAlerts:
@intriviousNov 08.2006 — Glad to here. Right, it simply keeps the browser from seeing the code as actual tags.

Does anyone know if there are anyways to get around htmlentities()?
×

Success!

Help @dotancohen 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...