Jump to content


Photo

validating textarea


  • Please log in to reply
1 reply to this topic

#1 mrjameer

mrjameer
  • Members
  • PipPipPip
  • Advanced Member
  • 102 posts

Posted 27 October 2006 - 07:14 AM

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

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 27 October 2006 - 07:20 AM

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.
<?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";

?>


heres a quick form example

<?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>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users