Home > Web Front-end > JS Tutorial > Share two simple JS codes to prevent SQL injection_javascript skills

Share two simple JS codes to prevent SQL injection_javascript skills

WBOY
Release: 2016-05-16 15:05:46
Original
2209 people have browsed it

1. URL address injection prevention:

//过滤URL非法SQL字符 
var sUrl=location.search.toLowerCase(); 
var sQuery=sUrl.substring(sUrl.indexOf("=")+1); 
re=/select|update|delete|truncate|join|union|exec|insert|drop|count|'|"|;|>|<|%/i; 
if(re.test(sQuery)) 
{ 
  alert("请勿输入非法字符"); 
  location.href=sUrl.replace(sQuery,""); 
} 
Copy after login

2. Input text box anti-injection:

/防止SQL注入 
 2function AntiSqlValid(oField ) 
 3{ 
 4  re= /select|update|delete|exec|count|'|"|=|;|>|<|%/i; 
 5  if ( re.test(oField.value) ) 
 6  { 
 7  //alert("请您不要在参数中输入特殊字符和SQL关键字!"); //注意中文乱码 
 8  oField.value = "; 
 9  oField.className="errInfo"; 
10  oField.focus(); 
11  return false; 
12  } 
Copy after login

Add the following method to the input text box that needs to be protected against injection:

txtName.Attributes.Add("onblur", "AntiSqlValid(this)");//Prevent Sql script injection

The above article sharing two simple JS codes to prevent SQL injection is all the content shared by the editor. I hope it can give you a reference, and I hope you will support Script Home more.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template