Jump to content

[SOLVED] PHP Script to block Porn Terms


ArizonaJohn

Recommended Posts

Hello,

 

The code below works great.  It takes in a variable called "name" from a simple HTML form and creates a new table in a MySQL database called the variable "name."  It allows the user to start a new table and name a new table.  This is exactly what I want.

 

However, I would like to prevent the user from creating new tables with pornographic names.  I was thinking that it would require me to add an IF statement before the code below, something like if $_POST['name']= 'sex', 'porn', etc., but I'm not sure what action to implement if this condition is true.

 

How could I do this?

 

Thanks in advance,

 

John

 

 

<?php

if (isset($_POST['name']) && !empty($_POST['name'])) {
mysql_connect("mysqlv3", "username", "password") or
die(mysql_error());
mysql_select_db("sand2") or die(mysql_error());

$table = mysql_real_escape_string($_POST['name']);

$query = "CREATE TABLE `$table` (id INT(11) NOT NULL auto_increment, site VARCHAR(150) NOT NULL, votes_up BIGINT(9) NOT NULL, votes_down BIGINT(9) NOT NULL, PRIMARY KEY(id), UNIQUE (site))";
$result = mysql_query($query) or die(mysql_error());


}

?>

Link to comment
https://forums.phpfreaks.com/topic/158990-solved-php-script-to-block-porn-terms/
Share on other sites

<?php

function check_porn_terms($input){
     $porn_terms = array("porn", "sex", "tits", "cock", "penis", "vagina", "pussy", "itakeithard", "hard_cock", "really_hard_cock", "suckmydickbitch", "fuck", "me", "good"); //add terms here
     foreach($porn_terms as $term){
          if(substr_count($input, $term) > 0) return false;
     }

     return true;
}

if (isset($_POST['name']) && !empty($_POST['name'])) {
mysql_connect("mysqlv3", "username", "password") or
die(mysql_error());
mysql_select_db("sand2") or die(mysql_error());

if(!check_porn_terms($_POST['name'])) die("No porn!");

$table = mysql_real_escape_string($_POST['name']);

$query = "CREATE TABLE `$table` (id INT(11) NOT NULL auto_increment, site VARCHAR(150) NOT NULL, votes_up BIGINT(9) NOT NULL, votes_down BIGINT(9) NOT NULL, PRIMARY KEY(id), UNIQUE (site))";
$result = mysql_query($query) or die(mysql_error());


}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.