Jump to content


Photo

stop words in database with array valadation


  • Please log in to reply
10 replies to this topic

#1 redarrow

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

Posted 08 June 2006 - 12:07 PM

Advance thank you.

The varable that holds the information is $message.

how can i valadate what words are in the message verable like this.

example:


$words=array("@" , "{ ","   ,    "$"  ,   " ("  ,   " } "  ,   "+"  ,  "," )

if($words==$message) {

echo " sorry charecter used not allowed";

}


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

#2 redarrow

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

Posted 08 June 2006 - 12:21 PM


This will replace the words not wanted but i want the same format but halting and echo a message cheers.


example:


$mess=array("@","*","$","'","{","}",";","<br>","mysql","connect","</br>","password","money","scam",".","com"
,"net","uk");

$message=str_replace($mess,"xxx" ,$message);

echo $message; 




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

#3 wisewood

wisewood
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts
  • LocationRotherham, England

Posted 08 June 2006 - 12:37 PM

foreach($mess as $val)
{

$string = $mesage;
if (eregi('$val', $string)) {
echo "Sorry, $val is not allowed.";
}

}

wisewood: proven fact, I am both wise, and wooden.

#4 redarrow

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

Posted 08 June 2006 - 12:46 PM


I got this so far but dosent work.

The varable is comming from the form so far before the database insert cheers.


$mess=array("@","*","$","'","{","}",";","<br>","mysql","connect","</br>","password","money","scam",".","com"
,"net","uk");

foreach($mess as $val) 
{

$string = $message;
if (eregi('$val', $string)) {
echo "Sorry, $val is not allowed.";
}

}

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

#5 redarrow

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

Posted 08 June 2006 - 12:59 PM


my error



Sorry, @ is not allowed.
Warning: ereg(): REG_BADRPT in C:\Program Files\Apache Group\Apache2\htdocs\collage\bands\mail\mail.php on line 43
Sorry, $ is not allowed.Sorry, . is not allowed

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

#6 wisewood

wisewood
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts
  • LocationRotherham, England

Posted 08 June 2006 - 01:33 PM

<?php
// only problem with this is that the word "coming" (for example) contains com, which is not allowed in your list.
// to get around this, put a space either side of com, filter for .com instead.

$message = "Your message here probably from a from on the previous page";
$mess=array("@", "*", "$", "'", "{", "}", "<br>", "mysql", "connect", "</br>", "password", "money", "scam", ".", "com", "net", "uk");

foreach($mess as $val)
{
$invalid = strpos($message, $val);
if($invalid===FALSE) { $count++; }

}

$array_count = count($mess, COUNT_RECURSIVE);
if($count==$array_count) { echo "Contains no illegal characters";}
else { echo "Your message contains illegal words / characters"; }

?>
wisewood: proven fact, I am both wise, and wooden.

#7 redarrow

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

Posted 08 June 2006 - 01:46 PM

Can some one brake this down to a babys level please lol cheers mate!

wisewood thats agrate bit of programming cheers please exsplain the code i only understand 50% of it beg you.

thanks redarrow.
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

#8 wisewood

wisewood
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts
  • LocationRotherham, England

Posted 08 June 2006 - 01:55 PM

// Your message that you want to check for illegal characters/words.
// $_POST[message] for example

$message = "Your message here probably from a from on the previous page";

// Your array of things that you do not want added to the database
$mess=array("@", "*", "$", "'", "{", "}", "<br>", "mysql", "connect", "</br>", "password", "money", "scam", ".", "com", "net", "uk");

// For each of the values in the $mess array, set it as $val and check if it exists in the $message variable.
// If it does not exist, add 1 to the $count variable.
foreach($mess as $val)
{
$invalid = strpos($message, $val);
if($invalid===FALSE) { $count++; }

}

// Count the number of words/characters that are in the array
$array_count = count($mess, COUNT_RECURSIVE);

// If the $count variable is the same as the $array_count variable, there are no illegal characters
if($count==$array_count) { echo "Contains no illegal characters";}

// if the $count and $array_count variables do not match, there must be at least one illegal character in the $message variable.
else { echo "Your message contains illegal words / characters"; }

?>

wisewood: proven fact, I am both wise, and wooden.

#9 redarrow

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

Posted 08 June 2006 - 02:06 PM

can you kindly exsplain this in easy terms cheers then solved thank you so much.
COUNT_RECURSIVE
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

#10 wisewood

wisewood
  • Members
  • PipPipPip
  • Advanced Member
  • 226 posts
  • LocationRotherham, England

Posted 08 June 2006 - 02:44 PM

COUNT_RECURSIVE is an optional component of the count() function.

if you were to use count($mess) and mess contained two arrays, the result would be 2.

However, by using count($mess, COUNT_RECURSIVE) you end up with it counting the contents of the $mess array, as well as the contents of any arrays stored within mess.

To be honest, in this case, i dont think its required, but i used it anyway.
wisewood: proven fact, I am both wise, and wooden.

#11 jimbob26

jimbob26
  • Members
  • Pip
  • Newbie
  • 3 posts

Posted 08 June 2006 - 03:42 PM

Maybe everyone has gone a little offtrack, all you need is a simple function called "in_array"
ie:

$message = "Hello ()";
$words=array("@","{","(","$","(","}","+");
for($i=0;$i<strlen($message);$i++) {
   if(in_array($message[$i],$words)) {
      echo "$message.<br>sorry charecter used not allowed. <b>".$message[$i]." at position $i</b>";
   }
}

Maybe thhat will help?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users