Table of Contents
php中$_GET与$_POST过滤sql注入的方法,_get_post
php过滤sql注入,新手
php 对于thinkphp的防sql注入跟过滤问题
Home php教程 php手册 php中$_GET与$_POST过滤sql注入的方法,_get_post

php中$_GET与$_POST过滤sql注入的方法,_get_post

Jun 13, 2016 am 09:22 AM
php sql injection

php中$_GET与$_POST过滤sql注入的方法,_get_post

本文实例讲述了php中$_GET与$_POST过滤sql注入的方法,分享给大家供大家参考。具体分析如下:

此函数只能过滤一些敏感的sql命令了,像id=1这种大家还是需要自己简单过滤了。

主要实现代码如下:

复制代码 代码如下:

if (!get_magic_quotes_gpc())
{
if (!empty($_GET))
{
$_GET  = addslashes_deep($_GET);
}
if (!empty($_POST))
{
$_POST = addslashes_deep($_POST);
}
$_COOKIE   = addslashes_deep($_COOKIE);
$_REQUEST  = addslashes_deep($_REQUEST);
}
function addslashes_deep($value)
{
if (empty($value))
{
return $value;
}
else
{
return is_array($value) ? array_map('addslashes_deep', $value) : addslashes($value);
}
}

希望本文所述对大家的PHP程序设计有所帮助。

php过滤sql注入,新手

我在PHP4环境下写了一个防SQL注入的代码,经过实际使用在PHP5下也兼容,欢迎大家使用修改,使用。
代码如下:
/*
sqlin 防注入类
*/
class sqlin
{

//dowith_sql($value)
function dowith_sql($str)
{
$str = str_replace("and","",$str);
$str = str_replace("execute","",$str);
$str = str_replace("update","",$str);
$str = str_replace("count","",$str);
$str = str_replace("chr","",$str);
$str = str_replace("mid","",$str);
$str = str_replace("master","",$str);
$str = str_replace("truncate","",$str);
$str = str_replace("char","",$str);
$str = str_replace("declare","",$str);
$str = str_replace("select","",$str);
$str = str_replace("create","",$str);
$str = str_replace("delete","",$str);
$str = str_replace("insert","",$str);
$str = str_replace("'","",$str);
$str = str_replace(""","",$str);
$str = str_replace(" ","",$str);
$str = str_replace("or","",$str);
$str = str_replace("=","",$str);
$str = str_replace("%20","",$str);
//echo $str;
return $str;
}
//aticle()防SQL注入函数
function sqlin()
{
foreach ($_GET as $key=>$value)
{
$_GE......余下全文>>
 

php 对于thinkphp的防sql注入跟过滤问题

用着个过滤传过来的值,这两个用之前先判断是否开启了
get_magic_quotes_gpc();没有开启的话用以下两个都可以过滤
mysql_real_escape_string();一般用于sql语句
addslashes();
例如:
if (!get_magic_quotes_gpc()) {
$lastname = addslashes($_POST[‘lastname’]);
//或者mysql_real_escape_string($_POST[‘lastname’])
} else {
$lastname = $_POST[‘lastname’];
}
 

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

How To Set Up Visual Studio Code (VS Code) for PHP Development

See all articles