TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-25-2009, 05:31 AM   #1 (permalink)
The Contributor
 
planepixel's Avatar
 
Join Date: Feb 2009
Posts: 28
Thanks: 10
planepixel is on a distinguished road
Default how to do form handling(validation and security) in php

Hi

form handling is little bit confusing. what is the best way to handle form data and make sure it is valid.
i read couple of tutorial which state that some method break if hosting company does not have some settings enabled.
how i design form and handle data independent of host specific setting.

thanks
planepixel is offline  
Reply With Quote
Old 06-25-2009, 10:30 AM   #2 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

There are many ways to do this and there wouldn't really be any point in showing you one way or another because in the end individual examples don't teach the ideas behind techniques. The basic idea is to be able to take some data input into the system (by a form, etc.) and through some method screen, filter, examine it to verify that it is something you are willing to allow into the application. There is no "best way".

With regards to host settings getting in the way of scripts, did your tutorials give any examples of individual settings which might be a problem?
Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
planepixel (06-26-2009)
Old 06-26-2009, 05:38 AM   #3 (permalink)
The Contributor
 
planepixel's Avatar
 
Join Date: Feb 2009
Posts: 28
Thanks: 10
planepixel is on a distinguished road
Default

Thanks for reply

tutorial warned about register_globals and magic_quotes.

i came across html purifier and it solved the purpose for the time being and another thing i tested is PEAR html quick form 2. i read documentation and went through code and whenever i got stuck i refereed php manual. it seems difficult task at start but as i followed i got the idea of it.

now my situation is much better. but i will keep reading and playing till i am able to understand it completely and create my own class to validate code to learn.
planepixel is offline  
Reply With Quote
Old 06-26-2009, 04:27 PM   #4 (permalink)
The Contributor
 
cecilia's Avatar
 
Join Date: May 2009
Location: LA, CA
Posts: 87
Thanks: 0
cecilia is on a distinguished road
Default

I do almost all of my form validation using javascript, I only use php when it has to check something on the database, record comparisons or collisions. Isnt it better to check it without leaving the form page if possible? Im supposed to use AJAX for the database check too, but ive beeen assigned to do some other thing argh.
cecilia is offline  
Reply With Quote
Old 06-26-2009, 05:03 PM   #5 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

It's fine to use JavaScript, and better for usability. However, to use ONLY JavaScript to validate forms is very bad. JavaScript is a client-side scripting language and can therefore be manipulated, and disabled.

If you're going to validate using JavaScript, then you still need the validation in PHP.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 06-26-2009, 08:52 PM   #6 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

NEVER use javascript for data processing, its use should be strictly stylistic. As Wild pointed out, javascript can be edited or disabled since the browser runs it.
__________________

Village Idiot is offline  
Reply With Quote
Old 06-27-2009, 12:20 AM   #7 (permalink)
The Contributor
 
cecilia's Avatar
 
Join Date: May 2009
Location: LA, CA
Posts: 87
Thanks: 0
cecilia is on a distinguished road
Default

Well, yeah, and I guess you can just make it submit to itself as an option to reduce the pages if you have to(some people just keep on making it a big deal). Thanks, Ive been trying to relearn a lot of bad ways that I picked up really so this helps, and redo what I did before too.
cecilia is offline  
Reply With Quote
Old 06-27-2009, 01:19 AM   #8 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by cecilia View Post
Well, yeah, and I guess you can just make it submit to itself as an option to reduce the pages if you have to(some people just keep on making it a big deal). Thanks, Ive been trying to relearn a lot of bad ways that I picked up really so this helps, and redo what I did before too.
Use this theory and you will do well:
If it is handled by the browser it can be modified, if it is sent from the client it can be played with.

HTML, HTTP (GET, POST and Referrer to name a few) and Javascript are all client side.
__________________

Village Idiot is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 11:30 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design