Jump to content

Archived

This topic is now archived and is closed to further replies.

mrjameer

validating textarea

Recommended Posts

hi,

can anybody please tell me how to avoid the user from entering any html code like '<','>', any other malicious characters in textarea using php.


thanks
mrjameer

Share this post


Link to post
Share on other sites
The main issue is to protect the database entrys so i advise to use the following.

addslasshes
trim

Also you can use all these from the link as i have provided.

http://uk2.php.net/addslashes


if both the examples below if the users has a < or > there be an error message.

good luck hope you understand all the best redarrow.

example1 for eregi.
[code]
<?php

$mes="hi there i am redarrow";

$ban=array('<','>');

foreach($ban as $x){


if(eregi($x,$mes)){


echo " bad word please try agin";
exit;

}
}
echo "good words congratulations";

?>
[/code]


heres a quick form example

[code]
<?php

if($_POST['submit']){

$ban=array('<','>');

foreach($ban as $x){


if(eregi($x,$mes)){


echo " bad word please try agin";
exit;

}
}
echo "good words congratulations";
}
?>

<form method="POST" action"">
<br>
please tell me what you think
of my site!
<br>
<input type="text" name="mes">
<br>
<br>
<input type="submit" name="submit" value="valadate words">
<br>
</form>
[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.