Gossamer Forum
Home : General : Perl Programming :

'if' statement maxlength

Quote Reply
'if' statement maxlength
I am looking for a quick 'if' statement to prevent hackers from pasteing into a field through a form to a cgi script .
Now I know I can use a maxlength through the HTML doc, but this won't prevent the problem (I have already considered) .
I assume it would be something like "

$MAXLENGTH= 10;
if ($field =~ ->'/$MAXLENGTH/) {
&to_long_sub;
exit;
}
I have also toyed with the idea of:

if ($form{'action'} eq "cgi_form"){

&to_long_sub unless $form{'-<'$MAXLENGTH'};
}
But none of the above are quite right ,infact some examples I have seen make me realise I am well off base. Can anyone supply me with a simple bit of 'if' code for the script please!
Quote Reply
Re: [classca] 'if' statement maxlength In reply to
Hi,

I am sure if you want to search for some special text. If just its length, below should work

$MAXLENGTH= 10;
if (length($field) > $MAXLENGTH) {
&to_long_sub;
exit;
}

Cheers,



Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [tandat] 'if' statement maxlength In reply to
Thank you Tandat, ever so much :) That's it ...