Go Back   CodingForums.com > :: Server side development > PHP > Post a PHP snippet

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-05-2007, 01:47 PM   PM User | #1
idalatob
Regular Coder

 
Join Date: Sep 2007
Location: Grahamstown, South Africa
Posts: 237
Thanks: 6
Thanked 17 Times in 17 Posts
idalatob is on a distinguished road
Simple spam removal.

Often when coders making additions to a database through user input they forget to ACTUALLY stop invalid input. This is a simple script (its designed to be simple) to help with spammers. (you could make it a function too)

No function
PHP Code:
<?php 
$message 
"<hm>What ever you want it to be.</hm>";
$message1 strip_tags($message);
if ((
strlen($message)) > (strlen($message1))){
    
$error true;
    echo(
"NO");
    } else {
    
//proceed with database addition
    
echo("yes");
    }
?>
As a function
PHP Code:
<?php 
function checkInput($message){
    
$message1 strip_tags($message);
    if ((
strlen($message)) > (strlen($message1))){
        
$error true;
        return 
false;
    } else {
        return 
true;
        }
}
?>
idalatob is offline   Reply With Quote
Old 09-05-2007, 01:52 PM   PM User | #2
Mwnciau
Regular Coder

 
Join Date: May 2006
Location: Wales
Posts: 820
Thanks: 1
Thanked 82 Times in 79 Posts
Mwnciau is on a distinguished road
If someone wanted to post some html code on a forum etc. using this would stop them posting, it would be easier to just use htmlspecialchars() which replaces < with &lt; and > with &gt;, so any html code will be shown rather than used in the page.
Mwnciau is offline   Reply With Quote
Old 09-05-2007, 02:50 PM   PM User | #3
idalatob
Regular Coder

 
Join Date: Sep 2007
Location: Grahamstown, South Africa
Posts: 237
Thanks: 6
Thanked 17 Times in 17 Posts
idalatob is on a distinguished road
Quote:
If someone wanted to post some html code on a forum etc. using this would stop them posting, it would be easier to just use htmlspecialchars() which replaces < with &lt; and > with &gt;, so any html code will be shown rather than used in the page.
true ... true. However this script is specifically for stopping any html code whatsoever. Have you ever seen forums destroyed by advertising? Its mainly because they strip tags yet show the message anyway. So you still get porn adds and stuff.
idalatob is offline   Reply With Quote
Old 09-05-2007, 02:59 PM   PM User | #4
rafiki
Senior Coder

 
rafiki's Avatar
 
Join Date: Aug 2006
Location: Floating around somewhere...
Posts: 2,034
Thanks: 18
Thanked 42 Times in 42 Posts
rafiki will become famous soon enough
PHP Code:
function remove_html_chars($string){
$html_chars = array(<, > ,e,t,c);
$string preg_replace("$html_chars"''$string);
return 
$string;

tihs would simply remove any charicters that you put in html_chars
__________________
Get Firefox Now
rafiki is offline   Reply With Quote
Old 03-14-2009, 07:54 PM   PM User | #5
student101
Regular Coder

 
student101's Avatar
 
Join Date: Nov 2007
Posts: 610
Thanks: 80
Thanked 13 Times in 13 Posts
student101 is on a distinguished road
Quote:
Originally Posted by idalatob View Post
PHP Code:
$message "<hm>What ever you want it to be.</hm>";
$message1 strip_tags($message);
if ((
strlen($message)) > (strlen($message1))){ 
I am not the best coder but a bit confused by this line;
PHP Code:
if ((strlen($message)) > (strlen($message1))){ 
Is that just a checking method to continue with the if then }else{
I don't think that having the if then else is needed, it will be greater than the stripped message.
PHP Code:
$message "<html>What ever you want it to be.</html>";
$message1 strip_tags($message);
//proceed with database addition 
__________________
Thanks for your support!
Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

Give thanks & resolve when done :thumbsup:
student101 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 01:41 AM.


Advertisement
Log in to turn off these ads.