Do you use PDO to filter user input?

Source: Internet
Author: User
How to filter if you use it?

Reply content:

How to filter if you use it?

Simple filtering definitely needs to be filtered, like data length, data type, and so on, PDO just solves the problem of SQL injection. Other procedural logic problems have to be solved by themselves.

It is better to filter it out, although PDO preprocessing can prevent SQL injection. Like intval ; trim These simple character processing is not much to say. Filter mainly consider some special characters, as follows I deal with the character of a method, you can refer to, I hope to help you

/** * description 过滤转义POST|GET的数据 */function isEscape($val, $isboor = false) {    if (! get_magic_quotes_gpc ()) {        $val = addslashes ( $val );    }    if ($isboor) {        $val = strtr ( $val, array (                "%" => "\%",                "_" => "\_"         ) );    }    return $val;}

PHP version <=5.3.6 my local test set setattribute (Pdo::attr_emulate_prepares, false) also local processing prepare, do not know is not my test problem, tested two PHP version PHP 5.2.3/5.2.17

The pit will be filtered! Also filtering XSS, etc.

Like XSS.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.