SQL防注入代码一

<?php
if (!function_exists (quote))
{
function quote($var)
{
if (strlen($var))
{
$var=!get_magic_quotes_gpc() ? $var : stripslashes($var);
$var = str_replace("'","'",$var);
}
return "'$var'";
}
}
if (!function_exists (hash_num)){
function hash_num($input)
{
$hash = 5381;
for ($i = 0; $i < strlen($str); $i++)
{
$c = ord($str{$i});
$hash = (($hash << 5) + $hash) + $c;
}
return $hash;
}
}
?>


<?php
include_once('common.php');
var_dump(hash_num('dddd'));
if(empty($_GET))
{
$_GET = array('age'=>'99','name'=>'a'b\'c";','note'=>"a'b'nc#");
}
$age = (int)$_GET['age'];
$name = quote($_GET['name']);
$note = quote($_GET['note']);
$sql = "INSERT INTO `tb` ( `age`, `name`, `note`) VALUES
( $age, $name, $note)";
var_dump($sql);
?>

SQL防注入代码二

<?php
$magic_quotes_gpc = get_magic_quotes_gpc();
@extract(daddslashes($_COOKIE));
@extract(daddslashes($_POST));
@extract(daddslashes($_GET));
if(!$magic_quotes_gpc) {
$_FILES = daddslashes($_FILES);
}

function daddslashes($string, $force = 0) {
if(!$GLOBALS['magic_quotes_gpc'] || $force) {
if(is_array($string)) {
foreach($string as $key => $val) {
$string[$key] = daddslashes($val, $force);
}
} else {
$string = addslashes($string);
}
}
return $string;
}
?>

SQL防注入代码三

function inject_check($sql_str)

{
$check = eregi('select|insert|update|delete|'|/*|*|../|./|union|into|load_file|outfile', $sql_str);
if ($check)

{
echo "输入非法注入内容!";
exit ();
}

else

{
return $sql_str;
}
}
function checkurl()

{
if
(preg_replace("/https教程?://([^:/]+).*/i", "1",
$_server['http_referer']) !== preg_replace("/([^:]+).*/", "1",
$_server['http_host'])) {
header("location: http://s.jb51.net");
exit();
}
}


checkurl();
$str = $_get['url'];
inject_check($sql_str);

摘自:http://www.codesky.net/article/201202/164551.html

PHP之SQL防注入代码集合(建站常用)的更多相关文章

  1. 特殊字符的过滤方法,防sql防注入代码的过滤方法

    特殊字符的过滤方法 function strFilter($str){ //特殊字符的过滤方法 $str = str_replace('`', '', $str); $str = str_replac ...

  2. PHP之SQL防注入代码(360提供)

    <?php class sqlsafe { private $getfilter = "'|(and|or)\\b.+?(>|<|=|in|like)|\\/\\*.+?\ ...

  3. sql防注入代码

    function defend_sql($string, $force = 1) { $preg = "select|insert|and|or|update|delete|\'|\/\*| ...

  4. SQL防注入程序 v1.0

    /// ***************C#版SQL防注入程序 v1.0************ /// *使用方法: /// 一.整站防注入(推荐) /// 在Global.asax.cs中查找App ...

  5. sql 防注入 维基百科

    http://zh.wikipedia.org/wiki/SQL%E8%B3%87%E6%96%99%E9%9A%B1%E7%A2%BC%E6%94%BB%E6%93%8A SQL攻击(SQL inj ...

  6. SQL防注入程序

    1.在Global.asax.cs中写入: protected void Application_BeginRequest(Object sender,EventArgs e){      SqlIn ...

  7. PHP SQL防注入

    过年前后在做一个抽奖的东西,需要用户填写中奖信息,为了防止非法用户对数据库进行入侵神马的,于是写下基本的防注入语句,需要用的可以自己封装成一个function. $str = str_replace( ...

  8. 浅谈 C# SQL防注入

    1#region 防止sql注入式攻击(可用于UI层控制)  2  3///   4/// 判断字符串中是否有SQL攻击代码  5///   6/// 传入用户提交数据  7/// true-安全:f ...

  9. Mybatis是如何实现SQL防注入的

    Mybatis这个框架在日常开发中用的很多,比如面试中经常有一个问题:$和#的区别,它们的区别是使用#可以防止SQL注入,今天就来看一下它是如何实现SQL注入的. 什么是SQL注入 在讨论怎么实现之前 ...

随机推荐

  1. AFNetworking2.4.1 解析

    http://wenku.baidu.com/view/6ec734a84028915f814dc26d.html

  2. 在浏览器中打开本地应用(iOS)

    在浏览器中点击跳转到本地应用的方法(如果本地没有安装的话) 然后在浏览器中输入tianxiang://就能打开这个应用了 ................省略 遇到一个12年还是初中的小朋友,

  3. MVC 构造

    // // View.h // UI5_HomeWork // // Created by zhangxueming on 15/7/2. // Copyright (c) 2015年 zhangxu ...

  4. mysql 存储过程详解 存储过程

    mysql存储过程详解 1.      存储过程简介         我们常用的操作数据库语言SQL语句在执行的时候需要要先编译,然后执行,而存储过程(Stored Procedure)是一组为了完成 ...

  5. (转)互联网保险O2O平台微服务架构设计

        关于架构,笔者认为并不是越复杂越好,而是相反,简单就是硬道理也提现在这里.这也是微服务能够流行的原因,看看市场上曾经出现的服务架构:EJB.SCA.Dubbo等等,都比微服务先进,都比微服务功 ...

  6. git与github

    Git-版本控制,多人协作,分布式: Github-开源项目,远程仓库: 我在github上建立了一个仓库 https://github.com/abcd/2016ife: 现在我要把它下载到本地: ...

  7. 【leetcode】368. Largest Divisible Subset

    题目描述: Given a set of distinct positive integers, find the largest subset such that every pair (Si, S ...

  8. WPF 绑定三(绑定List中指定的字符串)

    xaml: <Window x:Class="WpfApplication1.Window3" xmlns="http://schemas.microsoft.co ...

  9. PHP实现根据浏览器跳转不同语言页面代码

    以下是对使用PHP实现根据浏览器跳转不同语言页面的代码进行了介绍,需要的朋友可以过来参考下 代码: <?php /** * 根据不同浏览器跳转不同页面 * 来源:www.jbxue.com * ...

  10. HDU 2669 第六周 I题

    Description The Sky is Sprite.  The Birds is Fly in the Sky.  The Wind is Wonderful.  Blew Throw the ...