4058d6b5dc2bfd92fd7f7f9a13eb61a6

Lets say I am building a forum, and I am sanitizing a forum post submitted by a user.

The users submits a post from a text field name "text".
It goes into the back-end of the code where it is being sanitize.

$_POST['text']

What would be the best approach to sanitize a forum post?

My approach would be:

- Prepare through **sprintf**.
- Use **htmlentities** to stop Html being outputted.
- Use *shortcodes* to customize the post's style.
- Then Query a Insert into Database.

When I want to Get this information. I can simply **echo** it out.

Is this good enough or am I missing something?

<?php

$text = htmlentities($_POST['text']);
$query = sprintf("INSERT INTO $table (`user_id`, `post_text`) VALUES ($d, $s);",$user_id,$text);

customQueryFunction($query);

?>

Refactorings

No refactoring yet !

D134a5da18b14a209b0099c720fd2e36

NullUserException

August 10, 2010, August 10, 2010 19:33, permalink

1 rating. Login to rate!

First of all this would be a great question for SO, just post it there. This is a short and objective enough question.

- This is not safe from SQL Injections since by default htmlentities() does not convert quotes (' and ")
- You can prepare through actual prepared statements. Google "PDO Prepared Statements". You should also escape your input using mysql_real_escape_string() when appropriate.
- Storing code that's been converted with htmlentities() increases the size of your database. If you can remember to call htmlentities() every time before you output it, you'd save some space.

Not only that but it also removes the ability to allow certains users (admins for example) to insert HTML.

- An alternative to BBCodes would be having a limited subset of HTML elements permitted (this can be made flexible by allowing different roles to have be allowed to use different tags); and use something like HTMLPurifier to filter your HTML tags.

F9a9ba6663645458aa8630157ed5e71e

Ants

August 10, 2010, August 10, 2010 19:34, permalink

No rating. Login to rate!

You also need to prevent SQL in injection. Consider what happens in the posted text is:
Hi'); DROP TABLE $table; --

I love this XKCD cartoon to remind me of SQL injection attacks: http://xkcd.com/327/

I think that using the ENT_QUOTES parameter with htmlentities() function may help a little bit.

4058d6b5dc2bfd92fd7f7f9a13eb61a6

Anri

August 10, 2010, August 10, 2010 20:28, permalink

No rating. Login to rate!

@NullUserException

Is there a difference between sprintf and PDO Prepare statements?
I am using Wordpress's Prepare Function, and with sprintf, they are very similar.
The only thing missing in my sanitizing would be escaping it from possible SQL injection correct?

Oh. And about SO, I wasn't very sure whether this would have been a valid question for SO. But I suppose it was in your statement.

So the revision would be.

<?php
$text = mysql_real_escape_string($_POST['text']);
$query = sprintf("INSERT INTO $table (`user_id`, `post_text`) VALUES ($d, $s);",$user_id,$text);

?>

<?php
echo htmlentities($text);
?>
9e11a35edc5b304dc68aa9ceac104aa9

VanTMark

August 22, 2010, August 22, 2010 06:23, permalink

No rating. Login to rate!

Zapatorinus is good. I am fool adjflkfadf dsjje <a href=http://sdlklerwer.jsd>sdfjfwe</a> angfjsdf. Sorry me...

F72ce3e8360a1241d2a061946b9cf204

starringmoviest

August 24, 2010, August 24, 2010 19:28, permalink

No rating. Login to rate!

hi i am new here just wana say hi to all members

475a3a4994063e66af510dab445d5156

Flowerbuth

August 24, 2010, August 24, 2010 20:52, permalink

No rating. Login to rate!

What flowers do you like?

1e4a974f84b41f33fb3ca00f113b2dd4

Loupepabpaush

December 12, 2010, December 12, 2010 09:31, permalink

No rating. Login to rate!

motorized ride on car auto parts chevy carburetor mini no bake cheesecake 1982 suzuki gsx1000 katana 2006 dodge sprinter 2500 blue book price

296d4ab9161f8718dcdf66cfe5d6a9f4

skisshop

December 20, 2010, December 20, 2010 05:36, permalink

No rating. Login to rate!

20k Spyder Aspen Ski Mens Jacket Coat Xl Herren 54 More From Seller. In stock at . Spyder Ski Wear for Less. Shop Our Wide Range of Spyder Ski Gear.Cross Country (XC) Downhill (DH) Freeride / All Mountain Hardtail Cross Country (XC) Dirt Jump Freeride Womens Ladies Womens Ladies
<a href=http://bngfdjkhghgd.t35.com>nz ski resort weather</a>

517bfd72599f907c985a9a3dd5f918b7

JasonNT

December 21, 2010, December 21, 2010 17:28, permalink

No rating. Login to rate!

delete plz

Da5a45701948434bea644e7820bae6f7

semsomign

December 22, 2010, December 22, 2010 22:55, permalink

No rating. Login to rate!

Hey, I wanted to know of any tool or i think you call them Aps to show you the best deals? I'm aware that you can type in a search in google and you only get the advertisers that paid the most, not the best deals. Any help would be great.

43dfb90ca0fb1a0737e03d4dd593d1d9

Sylvitan

December 31, 2010, December 31, 2010 05:30, permalink

No rating. Login to rate!

Hello ! I'm new on this forum, hope to talk to you soon :)
I love carsn seotons and tuning, and you ?

01d0d26a38d879e92ba634f79faa75f7

Gold Load

January 10, 2011, January 10, 2011 09:50, permalink

No rating. Login to rate!

Spectacular blog, by means of lover that wrote so often. The pipe reaction that writes to-date bumf :)

B5358892e97b34f09003d4d2886821ce

mrtesty

January 17, 2011, January 17, 2011 22:50, permalink

No rating. Login to rate!

Delete shis text plz. Sorry

748b5d728a68d887086159d22c387017

turkeyegypt

February 1, 2011, February 01, 2011 15:15, permalink

No rating. Login to rate!

Hello all! check pliz
somebody know information about egypt miting in that moment? and who have photo from Egypt? plz give me a link to see this photo!!
sorry if i post this messege wrong topic.

Fxxxxcking dirty egyptians!!!

2711775bcf60e5a74ebaea54084a68b6

toncagstito

February 17, 2011, February 17, 2011 07:36, permalink

No rating. Login to rate!

delete

430e5530b77251b8fe879aa5d2717249

TheAiriona

February 17, 2011, February 17, 2011 15:36, permalink

No rating. Login to rate!

How do you do?

50fb095813a717004e79821826682fc9

ByncopposyMup

March 10, 2011, March 10, 2011 14:33, permalink

No rating. Login to rate!

Do you have inspiron 1721 raid, hp pavilion model a810n and hp pavilion dv5-1007 review?

0ec8729d2605923781f28be599c1f0e1

Braipleri

April 30, 2011, April 30, 2011 12:11, permalink

No rating. Login to rate!

Сохраненная копия Обезьяны идут по своим делам объявления знакомства для секса красноярск не Пролетел месяц, дружба любовь. Коммерческая недвижимость 23 апр 2011 доска объявлений города Ноябрьска Объявления о продаже водного транспорта .Авто-аудио и видео Поиск интересующего автомобиля среди предложений частных лиц и автомобильных компаниях.Было тяжеловато совмещать учебу, работу и бокс, но я учился только на четверки Я хочу оставить именно след!Пришлите нам письмо со следующими данными на почту: 15 окт 2005 Для всех нас было бы нелишним сходить на прием к кардиологу.Аренда квартир без посредников и по лучшим ценам на рынке благодаря доступу к базе . Рубрика: техническая площадь; сдам: в этой рубрике публикуются объявления о сдаче в аренду офисных 06. Объявления о продаже и аренде квартир, комнат, домов, участков, офисов и коммерческой недвижимости в Санкт-Петербурге и Ленинградской области.

59e2feb4a463d87134bab49d6d587fa9

Anastasssia

June 3, 2011, June 03, 2011 01:44, permalink

No rating. Login to rate!

Купила аппарат Canon 4450 с картриджем canon 728. Не могу найти совместимый картридж. Оригинальные очень дорогие!
Может кто подскажет, что делать, а то напечатал пачку бумаги и кончился...

81ee518a1181fd0766c4ec89e5d7a079

flellareire

September 4, 2011, September 04, 2011 11:51, permalink

No rating. Login to rate!

Thanks mate... just dropped by.!!!!! Will look for BIKE STN when we get to Seattle. Still in Buenos Airies.!!!!!

81ee518a1181fd0766c4ec89e5d7a079

NarbrommagDug

September 7, 2011, September 07, 2011 05:57, permalink

No rating. Login to rate!

Thanks mate... just dropped by.!!!!! Will look for BIKE STN when we get to Seattle. Still in Buenos Airies.!!!!!

5e536dbc473469d0af1d44020a4b0bab

abrantTar

September 19, 2011, September 19, 2011 17:19, permalink

No rating. Login to rate!

Thanks mate... just dropped by.!!!!! Will look for BIKE STN when we get to Seattle. Still in Buenos Airies.!!!!!

5e536dbc473469d0af1d44020a4b0bab

Cacralley

September 20, 2011, September 20, 2011 21:24, permalink

No rating. Login to rate!

Thanks mate... just dropped by.!!!!! Will look for BIKE STN when we get to Seattle. Still in Buenos Airies.!!!!!

Cdfc2f06696445ba97acf79c1f643421

Peceallency

October 11, 2011, October 11, 2011 06:25, permalink

No rating. Login to rate!


charter furniture addison
unique painted furniture
sharpen kitchen knives
bath discount tub
ameriplan home business


lowes home improvement district offices
renovating your kitchen
decorating a small kitchen
how to install a kitchen faucet
polywood patio furniture


asheville builder developer home
building cost home material
unique furniture store
carsons of high point furniture
dealer furniture new

772ebcc4c3ef8a1dab8b677c0c45c588

rorkedmedia

November 1, 2011, November 01, 2011 12:16, permalink

No rating. Login to rate!

KOVAL ! why do you only respond to people who threaten to unsubscribe... what about me....Id like a shout out too ....I watched all your videos....TWICE.....i loved you when you weren't? famous.... *sigh*

9e67cf08593df723202d8a7083072f67

Deannyten

November 15, 2011, November 15, 2011 17:11, permalink

No rating. Login to rate!

KOVAL ! why do you only respond to people who threaten to unsubscribe... what about me....Id like a shout out too ....I watched all your videos....TWICE.....i loved you when you weren't? famous.... *sigh*

F0331c47e300bd43483bcce637523003

vostenofs

November 16, 2011, November 16, 2011 14:48, permalink

No rating. Login to rate!

BloombergFTR, GS, CVS, DHI, PM - Wednesday Notable Stocks with Volume at NYSEHealth Talk & YouCVS Caremark Corporation (CVS Caremark) is a pharmacy healthcare provider in the United States.

76ba81d8bf91ab0042fc3476b487a408

Peeleaskirl

November 19, 2011, November 19, 2011 19:00, permalink

No rating. Login to rate!

BloombergFTR, GS, CVS, DHI, PM - Wednesday Notable Stocks with Volume at NYSEHealth Talk & YouCVS Caremark Corporation (CVS Caremark) is a pharmacy healthcare provider in the United States.

1a295524b1ce0c250072963eead13184

nocaoccub

November 12, 2011, November 12, 2011 07:59, permalink

No rating. Login to rate!

BloombergFTR, GS, CVS, DHI, PM - Wednesday Notable Stocks with Volume at NYSEHealth Talk & YouCVS Caremark Corporation (CVS Caremark) is a pharmacy healthcare provider in the United States.

A00cef0bc511c9c4f6b8fa1c81e98917

erunnyutesy

November 15, 2011, November 15, 2011 07:44, permalink

No rating. Login to rate!

BloombergFTR, GS, CVS, DHI, PM - Wednesday Notable Stocks with Volume at NYSEHealth Talk & YouCVS Caremark Corporation (CVS Caremark) is a pharmacy healthcare provider in the United States.

9567bd4ee5ea6fdc6ff66c69e5c0b968

Rilsotbloth

November 20, 2011, November 20, 2011 18:12, permalink

No rating. Login to rate!

BloombergFTR, GS, CVS, DHI, PM - Wednesday Notable Stocks with Volume at NYSEHealth Talk & YouCVS Caremark Corporation (CVS Caremark) is a pharmacy healthcare provider in the United States.

21eb0f5dc6dd6cfa74971bb4bda87412

deermcregmene

December 22, 2011, December 22, 2011 20:25, permalink

No rating. Login to rate!

BloombergFTR, GS, CVS, DHI, PM - Wednesday Notable Stocks with Volume at NYSEHealth Talk & YouCVS Caremark Corporation (CVS Caremark) is a pharmacy healthcare provider in the United States.

8afb24cbb37771d3604cf1b175fa9c58

boubjesee

November 27, 2011, November 27, 2011 07:40, permalink

No rating. Login to rate!

BloombergFTR, GS, CVS, DHI, PM - Wednesday Notable Stocks with Volume at NYSEHealth Talk & YouCVS Caremark Corporation (CVS Caremark) is a pharmacy healthcare provider in the United States.

F8060a0ec00043c539a3f143e282cf4f

elafDeema

November 27, 2011, November 27, 2011 19:40, permalink

No rating. Login to rate!

KOVAL ! why do you only respond to people who threaten to unsubscribe... what about me....Id like a shout out too ....I watched all your videos....TWICE.....i loved you when you weren't? famous.... *sigh*

1f1d40f4a0279daf80fbbf32dc512481

Anaedlypneula

December 5, 2011, December 05, 2011 09:17, permalink

No rating. Login to rate!

cvs pharmacy h57 http://exclusiverx.com/products/metoclopramide.htm pergolide equine canadian pharmacy

339917717d728686e8dfa823242d13c8

SWASIAWOUMS

December 24, 2011, December 24, 2011 22:08, permalink

No rating. Login to rate!

BloombergFTR, GS, CVS, DHI, PM - Wednesday Notable Stocks with Volume at NYSEHealth Talk & YouCVS Caremark Corporation (CVS Caremark) is a pharmacy healthcare provider in the United States.

92e12544ec63b2bd1950b11f78628dff

addichaccipsy

December 28, 2011, December 28, 2011 11:02, permalink

No rating. Login to rate!

KOVAL ! why do you only respond to people who threaten to unsubscribe... what about me....Id like a shout out too ....I watched all your videos....TWICE.....i loved you when you weren't? famous.... *sigh*

945f35eccee794a84869465a3be349c5

FabsBlammaKah

December 28, 2011, December 28, 2011 20:22, permalink

No rating. Login to rate!

KOVAL ! why do you only respond to people who threaten to unsubscribe... what about me....Id like a shout out too ....I watched all your videos....TWICE.....i loved you when you weren't? famous.... *sigh*

Afe8e8f8d73ac17b6f156a28337a3495

PienWonee

December 29, 2011, December 29, 2011 01:52, permalink

No rating. Login to rate!

KOVAL ! why do you only respond to people who threaten to unsubscribe... what about me....Id like a shout out too ....I watched all your videos....TWICE.....i loved you when you weren't? famous.... *sigh*

0e18fa150b731e599d8dd32b5202ce82

Invoixmoott

December 29, 2011, December 29, 2011 21:36, permalink

No rating. Login to rate!

KOVAL ! why do you only respond to people who threaten to unsubscribe... what about me....Id like a shout out too ....I watched all your videos....TWICE.....i loved you when you weren't? famous.... *sigh*

56797e70a9cef3127328d0d7c5357efd

beistMuGseeks

December 29, 2011, December 29, 2011 22:13, permalink

No rating. Login to rate!

KOVAL ! why do you only respond to people who threaten to unsubscribe... what about me....Id like a shout out too ....I watched all your videos....TWICE.....i loved you when you weren't? famous.... *sigh*

46772bca7a2249035cec92de277c0391

Feriordedia

January 16, 2012, January 16, 2012 13:10, permalink

No rating. Login to rate!

KOVAL ! why do you only respond to people who threaten to unsubscribe... what about me....Id like a shout out too ....I watched all your videos....TWICE.....i loved you when you weren't? famous.... *sigh*

30fb57d76b404594e74434c5125ecc80

Waisistegleri

January 17, 2012, January 17, 2012 10:37, permalink

No rating. Login to rate!

For the sake of one hundred thousand is nothing to regret mite. ( kal-myts. )

67e848d8534562b18da9a586a6a831d6

Djimbo-STin

January 19, 2012, January 19, 2012 01:52, permalink

No rating. Login to rate!

The Company In-Disguise .Com
Glad to introduce you – private and Fully Automatic VPN Service!

In-Disguise. Com - Fully Automatic VPN service, you don’t have to waste time on:

1 - Search Supports if disconnected from a server, search for a standard installation “OpenVPN client”
spend time for installing downloaded configs to the program.
Troubleshoot the upgraded system for a stable connection to the VPN.
access to all servers for just 9 EURO.
DoubleVPN, OPENVPN and PPTP VPN - Access to 18 servers in 10 countries!
Subscribe to All Servers of Our Service for 9 Euro; 3 months = 20 Euro; 6 months = 35 Euro; 1 year = 55 Euro.

2 - Unique “VPN Client” is easy to install on all kinds of Operating Systems: MAC / Windows / Liinux!!!
Will allow you to switch easily between the VPN servers in USA / DE / UK / IT / NL / LU / EG / PA / RO / MY Continuing
In the near future our service will be available in Spain, Greece, Sweden, Mexico, Czech Republic, Poland, China, Belgium ...
Types of VPN connections included in a single subscription - DoubleVPN and OpenVPN.

3 - The program features an easy configuration of a VPN connection to your Internet: -automatically Block Internet Connection when Disconnected from a VPN.
- Automatic connection to the VPN when you turn on the Internet.

4 - Company Takes All Kinds Of Payments in Full Auto Mode!
WebMoney / Visa / Master Card / PayPal / Liberty Reserve / BitCoin / SMS and many others.
Our site is here in-disguise .com /?aff=69
Sincerely, In-Disguise .Com

========
Also,our Service has a unique N-tier, Private Partnership Program:

You will get 35% of total payments of your customers!
Registration only for an invite code - a code targeted at a single registration .
After registration you can become an Affiliated owner
Proposing an affiliation to your friends you can get up to 11% of their profits.
Our sister site is vpnincome .Com
If you are interested in our VPN Service or an Affiliation program, please refer all questions to :
ICQ: 6850058
E-mail: paul_okenfold@yahoo.com

67e848d8534562b18da9a586a6a831d6

ST-SlavaT

January 19, 2012, January 19, 2012 20:38, permalink

No rating. Login to rate!

The Company In-Disguise .Com
Glad to introduce you – private and Fully Automatic VPN Service!

In-Disguise. Com - Fully Automatic VPN service, you don’t have to waste time on:

1 - Search Supports if disconnected from a server, search for a standard installation “OpenVPN client”
spend time for installing downloaded configs to the program.
Troubleshoot the upgraded system for a stable connection to the VPN.
access to all servers for just 9 EURO.
DoubleVPN, OPENVPN and PPTP VPN - Access to 18 servers in 10 countries!
Subscribe to All Servers of Our Service for 9 Euro; 3 months = 20 Euro; 6 months = 35 Euro; 1 year = 55 Euro.

2 - Unique “VPN Client” is easy to install on all kinds of Operating Systems: MAC / Windows / Liinux!!!
Will allow you to switch easily between the VPN servers in USA / DE / UK / IT / NL / LU / EG / PA / RO / MY Continuing
In the near future our service will be available in Spain, Greece, Sweden, Mexico, Czech Republic, Poland, China, Belgium ...
Types of VPN connections included in a single subscription - DoubleVPN and OpenVPN.

3 - The program features an easy configuration of a VPN connection to your Internet: -automatically Block Internet Connection when Disconnected from a VPN.
- Automatic connection to the VPN when you turn on the Internet.

4 - Company Takes All Kinds Of Payments in Full Auto Mode!
WebMoney / Visa / Master Card / PayPal / Liberty Reserve / BitCoin / SMS and many others.
Our site is here in-disguise .com /?aff=69
Sincerely, In-Disguise .Com

========
Also,our Service has a unique N-tier, Private Partnership Program:

You will get 35% of total payments of your customers!
Registration only for an invite code - a code targeted at a single registration .
After registration you can become an Affiliated owner
Proposing an affiliation to your friends you can get up to 11% of their profits.
Our sister site is vpnincome .Com
If you are interested in our VPN Service or an Affiliation program, please refer all questions to :
ICQ: 6850058
E-mail: paul_okenfold@yahoo.com

67e848d8534562b18da9a586a6a831d6

Bingo-Super

January 20, 2012, January 20, 2012 15:05, permalink

No rating. Login to rate!

The Company In-Disguise .Com
Glad to introduce you – private and Fully Automatic VPN Service!

In-Disguise. Com - Fully Automatic VPN service, you don’t have to waste time on:

1 - Search Supports if disconnected from a server, search for a standard installation “OpenVPN client”
spend time for installing downloaded configs to the program.
Troubleshoot the upgraded system for a stable connection to the VPN.
access to all servers for just 9 EURO.
DoubleVPN, OPENVPN and PPTP VPN - Access to 18 servers in 10 countries!
Subscribe to All Servers of Our Service for 9 Euro; 3 months = 20 Euro; 6 months = 35 Euro; 1 year = 55 Euro.

2 - Unique “VPN Client” is easy to install on all kinds of Operating Systems: MAC / Windows / Liinux!!!
Will allow you to switch easily between the VPN servers in USA / DE / UK / IT / NL / LU / EG / PA / RO / MY Continuing
In the near future our service will be available in Spain, Greece, Sweden, Mexico, Czech Republic, Poland, China, Belgium ...
Types of VPN connections included in a single subscription - DoubleVPN and OpenVPN.

3 - The program features an easy configuration of a VPN connection to your Internet: -automatically Block Internet Connection when Disconnected from a VPN.
- Automatic connection to the VPN when you turn on the Internet.

4 - Company Takes All Kinds Of Payments in Full Auto Mode!
WebMoney / Visa / Master Card / PayPal / Liberty Reserve / BitCoin / SMS and many others.
Our site is here in-disguise .com /?aff=69
Sincerely, In-Disguise .Com

========
Also,our Service has a unique N-tier, Private Partnership Program:

You will get 35% of total payments of your customers!
Registration only for an invite code - a code targeted at a single registration .
After registration you can become an Affiliated owner
Proposing an affiliation to your friends you can get up to 11% of their profits.
Our sister site is vpnincome .Com
If you are interested in our VPN Service or an Affiliation program, please refer all questions to :
ICQ: 6850058
E-mail: paul_okenfold@yahoo.com

Afd225dd756e748c8504b59df06cef8d

Tawdielflyday

January 20, 2012, January 20, 2012 17:04, permalink

No rating. Login to rate!

KOVAL ! why do you only respond to people who threaten to unsubscribe. what about me....Id like a shout out too ....I watched all your videos....TWICE.....i loved you when you weren't? famous.... *sigh*

A121c48e6c9eef8adec2838944359955

KNEEDGINGTHOG

January 20, 2012, January 20, 2012 19:25, permalink

No rating. Login to rate!

KOVAL ! why do you only respond to people who threaten to unsubscribe... what about me....Id like a shout out too ....I watched all your videos....TWICE.....i loved you when you weren't? famous.... *sigh*

E43737dac874c9f246c79e66d3308fd8

papydiple

January 21, 2012, January 21, 2012 09:35, permalink

No rating. Login to rate!

KOVAL ! why do you only respond to people who threaten to unsubscribe... what about me....Id like a shout out too ....I watched all your videos....TWICE.....i loved you when you weren't? famous.... *sigh*

Your refactoring





Format Copy from initial code

or Cancel