MySQL Injection.... But allowing special characters...

Discussion in 'PHP' started by cyclotron, Aug 16, 2010.

  1. #1
    Hey there,

    I have a form where a user can input some text and it gets added to the database.

    ATM it is just inserted via mysql_real_escape_string(htmlspecialchars(... But this does not allow them to insert special characters like this:

    ◕‿◕ ☮✖ ✗ ✘ ♬ ♪ ♩ ♫ ♪ ☼ ✄ ✂ ✆ ✉ ✦ ✧ ♱ ♰ ♂ ♀ ☿ ❤ ❥ ❦ ❧

    If I remove the mysql real escape string it works, but it also allows them to insert iframes, scripts etc.

    Can I allow the symbols, but not the stupid shit like </a> tags, iframe tags, script tags etc?

    Thanks!
     
    cyclotron, Aug 16, 2010 IP
  2. jpratama

    jpratama Member

    Messages:
    31
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #2
    Did you already try strip_tags() function ? It's in the manual http://id2.php.net/manual/en/function.strip-tags.php.
    Example :
    <?php
    $text = '<p>Test paragraph.</p><!-- Comment --> <a href="#fragment">Other text</a>';
    echo strip_tags($text);
    echo "\n";
    
    // Allow <p> and <a>
    echo strip_tags($text, '<p><a>');
    ?>
    PHP:
     
    jpratama, Aug 16, 2010 IP
  3. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #3
    I think your table needs to be unicode compatible. Most default charset are latin1_general_ci, you will need utf8_unicode_ci
     
    Kaizoku, Aug 16, 2010 IP
  4. tech_tycoon

    tech_tycoon Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    use strip_tag first to remove html tags from text and then insert inset into table.otherwise iframe can go through it.
     
    tech_tycoon, Aug 16, 2010 IP