Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

php and forms

securing php forms



12:16 am on Aug 6, 2002 (gmt 0)

10+ Year Member

May I know some php'ers here on how do you make it sure that the forms (texarea, input, etc ...) are secure in a way that you filter out scripts that may cause intrusion to your site? is strip_tags secure enough?

post your script if you like. =)


8:14 pm on Aug 6, 2002 (gmt 0)

10+ Year Member

The trick here is not to remove all malicious code, but focus on allowing only legit text or whatever you're collecting.

What I usually do is simply define characters that I consider legit entries for example (maybe a comment box or something similar):

"A-Z", "a-z", "0-9", ",."

The next step is to identify ways that those characters can be used against your server. It will also depends if you insert the data in a database, this will add some complexity to the problem but if you're able to keep your legit characters set small, it shouldn't be to hard to cover the basic.

So your code could simply parse the input, keeping only the legit characters, possibly removing patterns you identified that could cause problems.

One little note. Since new exploits are discovered over time, I use only one validation file (that can serve different purposes) in a central location allowing me to update it pretty quickly.



8:27 pm on Aug 6, 2002 (gmt 0)

WebmasterWorld Senior Member nick_w is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Also, make sure the post vars really are post vars... use the $_POST['value'} array...



9:36 pm on Aug 6, 2002 (gmt 0)

10+ Year Member

Lots of useful information on PHP security here [hr.uoregon.edu].


12:21 am on Aug 7, 2002 (gmt 0)

10+ Year Member

$safe_vars = array();
foreach ($_POST as $key => $value) {
$safe_vars[$key] = htmlspecialchars($value);

Featured Threads

Hot Threads This Week

Hot Threads This Month