简体   繁体   English

检测HTML代码注入

[英]Detecting HTML Code Injection

Using the php strip_tag function to prevent HTML injection into my database I was wondering if there's any way I can detect if it's been used, ie the following: 使用php strip_tag函数来阻止HTML注入我的数据库我想知道是否有任何方法可以检测它是否已被使用,即以下内容:

if (strip_tags has been used/had any effect on the code) { error; if(strip_tags已被使用/对代码有任何影响){error; } }

I want to output an error the user letting them know that HTML tags cannot be used before hand instead of going straight to the db insertion. 我想输出一个错误,用户让他们知道HTML标签不能事先使用,而不是直接进入数据库插入。

Simply compare the sanitized data to the original data, and add a warning to the user if they don't match: 只需将已清理的数据与原始数据进行比较,如果不匹配,则向用户添加警告:

$data = $_GET["field_name"];
$sanitized = strip_tags($data);
if ($sanitized != $data) {
    echo "HTML not allowed.";
    // or...
    // throw new Exception("HTML not allowed.");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM