Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Sep 2007
    Location
    Grahamstown, South Africa
    Posts
    237
    Thanks
    6
    Thanked 17 Times in 17 Posts

    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;
            }
    }
    ?>

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Sep 2007
    Location
    Grahamstown, South Africa
    Posts
    237
    Thanks
    6
    Thanked 17 Times in 17 Posts
    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.

  • #4
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,043
    Thanks
    19
    Thanked 42 Times in 42 Posts
    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

  • #5
    Regular Coder student101's Avatar
    Join Date
    Nov 2007
    Posts
    634
    Thanks
    80
    Thanked 15 Times in 15 Posts
    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:


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •