Forum Moderators: coopster

Message Too Old, No Replies

What's wrong here

Once works, twice not

         

Lexur

8:15 am on Sep 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month




I'd like to filter posts with some tiles, so I copied the part of the script that previously filter the email addresses used to spam and changed the variables name.
It works perectly with emails but when I add this second task to filter those words you know, the script just stops (today I haven't access to php.ini to set up error messages on). Can you see something wrong there? Why one works and two don't?
This is the code:

===========================================

$banned_words = array();
$banned_words[] = 'buy biagra';
$banned_words[] = 'free #*$!';

foreach($banned_words as $bannedw) {
$bogus_text = $data['posttitle'];
if($bogus_text == $bannedw){
echo "<font color='#ff0000'><b>Ooopsss...</b><br>Sorry. You're posting so bad...</font>";
exit();
}
}
===========================================

ALKateb

10:59 am on Sep 3, 2009 (gmt 0)

10+ Year Member



try to print_r the $data array and see whether there is such index (posttitle)

and where is that part that checks the email? is it in another loop!?

penders

2:47 pm on Sep 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



today I haven't access to php.ini to set up error messages on

You don't need access to php.ini in order to enable error messages, you can use something like the following at the top of your script:

error_reporting(E_ALL ¦ E_STRICT); 
ini_set('display_errors','On');

if($bogus_text == $bannedw){

Does your $bogus_text equal $bannedw (in it's entirety) - which is what you have - or are you wanting to look for $bannedw within your $bogus_text (a partial match)?

andrewsmd

9:23 pm on Sep 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Where does $data come from you should do a var_dump on both of your variables and you will see why they aren't working
i.e.
foreach($banned_words as $bannedw) {
$bogus_text = $data['posttitle'];

var_dump($bogus_text);echo("<br>");
var_dump($data['posttitle']);

/*
if($bogus_text == $bannedw){
echo "<font color='#ff0000'><b>Ooopsss...</b><br>Sorry. You're posting so bad...</font>";
exit();
*/
}
}

Once you have an idea of what you are working with, you should be able to see what the problem with your if statement is. Penders is right, you can enable errors within the page for development purposes and then take them out at site launch. I usually have a required file that has my error reporting so I can include it in all pages and then just change the one file when we go live.