Jump to content

Advice on REGEXP in PHP


DamienRoche

Recommended Posts

Hi guys, I was wondering if anyone knows how to use a regexp to exclude special chars like < or " .

 

Basically, I do not want to process a form if a field contains <,",! or just anything that would be considered unusual and part of a scripting languages syntax.

 

Any thoughts?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/119879-advice-on-regexp-in-php/
Share on other sites

Thank you very much. That will come in handy.

 

I have also found another, less secure, way for any one else interested.

 

$illegal = "/\.|\"|\'|\,|\?|\(|\-|\<|\>|\;|&lt|&gt|\&|\=|\+|\@|\\\|\/|\:|\#|\!/";
$illegallax ="/\(|\<|\>|&lt|&gt|\=|\+|\@|\#|\!/";

if(preg_match($illegal,$first_field) 
|| preg_match($illegal,$second_field) 
|| preg_match($illegallax,$lax_field)
){
echo '<span style="color:red;">POSSIBLE HACK ATTEMPT!</span><br>
Details have been stored and sent to [email protected] who will investigate shortly.';
  return;
}

 

I'll look at using this in conjunction with the solution provided above. That way security should be pretty much water-tight on this front.

 

Thanks again.

Archived

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

×
×
  • Create New...

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.