Go Back   Gaming Gutter > Non-Gaming > Programming


Programming - All general programming discussion in here.

» Site Navigation
» Home
» FAQ
» Log in
User Name:

Password:

Not a member yet?
Register Now!
» Advertisement
» Recent Threads
Go to first new post Selling a few pets for NP
Yesterday 09:06 AM
Last post by matthew.n
Today 05:33 PM
3 Replies, 4 Views
Go to first new post Good AB list for newbies
09-03-2008 08:28 PM
Last post by Lanbo
Today 05:32 PM
7 Replies, 8 Views
Go to first new post COME TO VENT NAO!!
Today 01:00 PM
Last post by Snakebite
Today 05:32 PM
3 Replies, 4 Views
Go to first new post [B] FQD!
Today 05:24 PM
Last post by NextGenWarrior
Today 05:24 PM
0 Replies, 1 Views
Go to first new post Asda
08-28-2008 03:22 PM
by Pandox
Last post by Pandox
Today 05:23 PM
13 Replies, 14 Views
Reply
 
LinkBack Thread Tools Display Modes

 Help blocking words from $_Post
Old 03-24-2008, 11:51 PM   #1 (permalink)
Starwind237 Starwind237 is offline Gender Male
Underground
 
Starwind237's Avatar
 
Starwind237 is offline
Join Date: Jan 2007
Age: 18
Posts: 384
iTrader: 0 / 0%
Starwind237 Is Recognizable
Rep Power: 5
Question Help blocking words from $_Post

So I modded bug14's neater thingy to post contact details in a simple list. The only problem is I know stupid people will post a bunch of vulgar crap into it. That's why I want to incorporate a block list into.

This is what I'm currently trying but it blocks you no matter what you post.

PHP Code:
<?php
//Some variables...
$aim $_POST['aim'];
$yim $_POST['yim'];
$msn $_POST['msn'];
$name $_POST['name'];
$email $_POST['email'];

//Keeping out spam
//lowered badness level of words for younger GGers ^_^
$wordlist "crap|dang|shoot|sex";

if(
preg_replace("/\b($wordlist)\b/ie"'preg_replace("/./","*","\\1")'$name)){
    echo 
'You have tried to post something on the blocklist!';}

elseif(
preg_replace("/\b($wordlist)\b/ie"'preg_replace("/./","*","\\1")'$aim)){
    echo 
'You have tried to post something on the blocklist!';}

elseif(
preg_replace("/\b($wordlist)\b/ie"'preg_replace("/./","*","\\1")'$yim)){
    echo 
'You have tried to post something on the blocklist!';}
    
elseif(
preg_replace("/\b($wordlist)\b/ie"'preg_replace("/./","*","\\1")'$msn)){
    echo 
'You have tried to post something on the blocklist!';}    

elseif(
preg_replace("/\b($wordlist)\b/ie"'preg_replace("/./","*","\\1")'$email)){
    echo 
'You have tried to post something on the blocklist!';}    
    
    else{
            if(
$name!="") {
                
header("Location: view.php");
                
//writes contact information to text file.
                
$handle fopen("contacts.txt""a");
                    
fwrite($handle$name.".::.".$aim.".::.".$yim.".::.".$msn.".::.".$email."\r\n");
                
fclose($handle);
                }
            else {
                echo 
$html_one;
                echo 
'Please enter your name and full contact details.';
                }
                
        }
$html_one '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Please Enter Contact Details</title>
</head>'
;
    
?>
__________________

Last edited by Starwind237; 03-24-2008 at 11:54 PM.
  Reply With Quote

 
Old 03-25-2008, 11:14 AM   #2 (permalink)
rcadble rcadble is offline Gender Male
Underground
 
rcadble is offline
Join Date: Sep 2006
Posts: 227
iTrader: 0 / 0%
rcadble Is Recognizable
Rep Power: 7
Just use PHP's str_replace, it's a lot easier to use than regex.

Code:
<?php
$badwords = Array("crap", "dang", "shoot", "sex"); //add your words there
$aim = str_replace($badwords, "*BLOCKED*", htmlentities($_POST['aim'])));
$yim = str_replace($badwords, "*BLOCKED*", htmlentities($_POST['yim']));
$msn = str_replace($badwords, "*BLOCKED*", htmlentities($_POST['msn']));
$name = str_replace($badwords, "*BLOCKED*", htmlentities($_POST['name']));
$email = str_replace($badwords, "*BLOCKED*", strip_tags($_POST['email']));

if(!ereg("^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$", $email)) { //if it isn't a real email
	$errors .= "You entered an improperly formatted email address.<br>";
} 

if(stristr($aim, '*BLOCKED*') == true || stristr($msn, '*BLOCKED*') == true || stristr($yim, '*BLOCKED*') == true || stristr($name, '*BLOCKED*') == true || stristr($email, '*BLOCKED*') == true || ) {
	$errors .= "You entered a vulgar aim, yim, msn, name, or email.<br>";
}

if (strlen($name)==0 || strlen($email)==0) {
	$errors .= "Please do not enter a blank name or email.<br>";
}

if ($errors=="") {
	header("Location: view.php"); 
	$handle = fopen("contacts.txt", "a");
		fwrite($handle, $name.".::.".$aim.".::.".$yim.".::.".$msn.".::.".$email."\r\n");
	fclose($handle);
} else {
	echo $errors;
}
?>
I got rid of the $html_one crap since I didn't know what you were trying to do there, I'm sure you could easily reimplement that.
__________________
Omnipresent Autobuyer, the best free autobuyer.
Version 1.2
Always around, always present.
  Reply With Quote

 
Old 03-25-2008, 11:35 AM   #3 (permalink)
Starwind237 Starwind237 is offline Gender Male
Underground
 
Starwind237's Avatar
 
Starwind237 is offline
Join Date: Jan 2007
Age: 18
Posts: 384
iTrader: 0 / 0%
Starwind237 Is Recognizable
Rep Power: 5
$html1 was in bug14's original program. It basicly just set's up the title and a few other things.

Well, you had few typos that I had to debug. But, thanks to you I got it working!

Thanks a lot +rep
__________________

Last edited by Starwind237; 03-25-2008 at 11:54 AM.
  Reply With Quote
Reply

Bookmarks

Tags
blocklist, contact, php, starwind



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Powered by vBadvanced CMPS v3.0 RC2

All times are GMT -7. The time now is 05:33 PM.


vBulletin skin developed by: eXtremepixels
The contents of this webpage are copyright © 2006-2008 GamingGutter.com. All Rights Reserved.

Page generated in 0.11232090 seconds (100.00% PHP - 0% MySQL) with 19 queries