Hi folks.
I have created a submission form for people to add data to my database.
However, I would like somesort of security feature.
People could just spam and submit anything like swear words and or a link to another site.
The data that will be submitted are song lyrics.
so nothing less than 200 caracters should rearly be submitted.
I would like to know how i can detect the length of the submitted text. If it is less than 200 then sorry message.
more than 200 and it can be added to the database.
I hope someone can help.
Thanks
how to find the length of a string. ?
Moderators: egami, macek, gesf
- blake_ensenita
- New php-forum User
- Posts: 8
- Joined: Tue Jun 24, 2003 11:15 am
- Location: Vernon, BC, Canada
- Contact:
Use Javascript to validate it on the client side. Much faster and more efficient for the user.
Code: Select all
<script>
function fireFunction(){
variable = variable.length;
if(variable > 200){
alert("Your Message");
} else {
//Submit Your Form
}
}
</script>
Hi!
Ok it will look 'secure' if thanks to javascript, you display an alert box if the condition you want to be fulfilled (length of a field) is not.
But never forget that:
1) javascript is easily bypassed
2) in any case, you also have to check the content/syntax of the received fields in your php script on the server side!!
--> in your .php script, to know then length of a string, you need to use the function strlen (cf. http://www.php.net/strlen)
/Flood
Ok it will look 'secure' if thanks to javascript, you display an alert box if the condition you want to be fulfilled (length of a field) is not.
But never forget that:
1) javascript is easily bypassed
2) in any case, you also have to check the content/syntax of the received fields in your php script on the server side!!
--> in your .php script, to know then length of a string, you need to use the function strlen (cf. http://www.php.net/strlen)
/Flood