how to find the length of a string. ?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

ukmdb
New php-forum User
New php-forum User
Posts: 7
Joined: Sat Jun 21, 2003 12:56 pm

how to find the length of a string. ?

Postby ukmdb » Thu Jun 26, 2003 6:18 am

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

User avatar
blake_ensenita
New php-forum User
New php-forum User
Posts: 8
Joined: Tue Jun 24, 2003 11:15 am
Location: Vernon, BC, Canada
Contact:

Use Javascript

Postby blake_ensenita » Thu Jun 26, 2003 8:52 am

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>

Flood
New php-forum User
New php-forum User
Posts: 23
Joined: Tue Jun 24, 2003 4:49 am

Postby Flood » Fri Jun 27, 2003 1:48 am

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

ukmdb
New php-forum User
New php-forum User
Posts: 7
Joined: Sat Jun 21, 2003 12:56 pm

Postby ukmdb » Fri Jun 27, 2003 4:30 pm

thanks, guys.
just got to find now, how to stop people from
posting html / scripts.


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 1 guest

cron