Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-08-2013, 05:37 AM   PM User | #1
cgdtalent
New Coder

 
Join Date: Jan 2013
Posts: 33
Thanks: 10
Thanked 1 Time in 1 Post
cgdtalent is an unknown quantity at this point
Best Security Measures on User Input

On a form where users can input information, is it best to use strip_tags or use htmlentities or do both?

Also, is it necessary to filter the output on a form? For instance if all fields are required and they leave one field empty, then all the info they previously input is now displayed in the form fields again - should this be filtered going out as well?
cgdtalent is offline   Reply With Quote
Users who have thanked cgdtalent for this post:
salesmachine (02-08-2013)
Old 02-08-2013, 06:59 AM   PM User | #2
salesmachine
New to the CF scene

 
Join Date: Feb 2013
Posts: 2
Thanks: 3
Thanked 1 Time in 1 Post
salesmachine is an unknown quantity at this point
I think strip_tags will be the best measures for your category.
salesmachine is offline   Reply With Quote
Old 02-08-2013, 08:18 AM   PM User | #3
LearningCoder
Regular Coder

 
LearningCoder's Avatar
 
Join Date: Jan 2011
Location: The Pleiades
Posts: 848
Thanks: 67
Thanked 28 Times in 28 Posts
LearningCoder is an unknown quantity at this point
You could just use mysqli prepared statements, then when you want to display the data from the database to yourself or for whatever purpose, you could strip the tags then. I've always been told if you are re-displaying the data, then don't edit what the user has put. I used to strip all tags and as many 'special characters' as I could but was told to simply leave them in, then when you need to use that data, use those type of functions when re-displaying.

So now I leave the data as it is, insert using a prepared statement, then strip certain tags out, but only a few. I'm still not 100% sure on the way to handle data which you re-display on your website.

Regards,

LC

Last edited by LearningCoder; 02-08-2013 at 08:22 AM..
LearningCoder is offline   Reply With Quote
Old 02-08-2013, 09:56 AM   PM User | #4
devinmaking
Regular Coder

 
Join Date: Oct 2011
Posts: 236
Thanks: 11
Thanked 5 Times in 5 Posts
devinmaking has a little shameless behaviour in the past
I use PDO prepared statements to make sure input fields are safe.

I use it for anything i am dragging from a website including when fetching data from the url.
devinmaking is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:17 AM.


Advertisement
Log in to turn off these ads.