PHP防止数据库字符串登录SQL注入攻击
来源:互联网 发布:淘宝如何添加宝贝规格 编辑:程序博客网 时间:2024/05/16 19:52
<?php
header("Content-Type:text/html;charset=UTF-8");
// 数据库配置
include_once 'config.php';
// 获得传递参数
$user_name=isset($_request['user_name'])?$_request['user_name']:'';
$user_password=isset($_request['user_password'])?$_request['user_password']:'';
// 判断是否是非法字符串
// 防止SQL注入
if (empty($user_name)||empty($user_password)||!preg_match("/^[a-zA-Z0-9]{6,}$/", $user_name))
{
die('警告:输入错误!');
}
// 连接数据库
$conn=mysql_connect($Db_Server,$Db_User,$Db_Pwd);
// 判断连接是否成功
if (!$conn)
{
die("不能连接数据库,错误是: " . mysql_error());
}
// 数据库输出编码,应该与你的数据库编码保持一致。建议用UTF-8国际标准编码
mysql_query("set names 'utf8'");
// 打开数据库
$db_selected = mysql_select_db($Db_Name, $conn);
// 判断打开是否成功
if (!$db_selected)
{
die ("不能打开数据库,错误是: " . mysql_error());
}
// SQL语句
$sql ="select * from demo where user_name='".addslashes($user_name)."' AND password='".md5($user_password)."'";
// 查询SQL语句
$result = mysql_query($sql,$conn);
// 判断是否有数据
if (!$result)
{
die("查询失败: " . mysql_error());
}
// 循环读取数据
while($row = mysql_fetch_array($result))
{
// 读数据
echo $row['content'];
}
// 使用完毕关闭数据库连接
mysql_close();
?>
阅读全文
0 0
- PHP防止数据库字符串登录SQL注入攻击
- PHP中通过转义字符串防止SQL注入攻击
- PHP如何防止SQL注入式攻击
- php中防止sql注入攻击
- 防止 PHP的SQL 注入攻击
- PHP防止SQL注入和XSS攻击
- PHP防止注入攻击
- PHP---防止注入攻击
- SQL注入防止攻击
- 防止sql注入攻击
- 防止SQL注入攻击
- 防止SQL注入攻击
- 防止SQL注入攻击
- 防止sql注入攻击
- 防止SQL注入攻击
- 防止SQL注入攻击
- 防止SQL注入攻击
- c# 登录 防止sql注入 mysql数据库
- 阶乘因式分解
- 使用undo_retention参数与UNDO表空间GUARANTEE功能避免ORA-01555错误
- markdown数学公式编辑
- PullToRefresh上拉刷新下拉加载更多的使用
- 程序员到底该怎么找资源?
- PHP防止数据库字符串登录SQL注入攻击
- undo_retention 确定最优的撤销保留时间
- 12月7号
- Mysql
- 深入理解Spring 之 源码剖析AOP(XML配置方式)
- ACM 某种序列
- 经典面试题golang实现方式(一)
- 【算法】合并k个有序的链表-基于最小堆的思想
- python通过string运行代码