php 安全
如何不使用prepared statment,而是用过滤的方法避免SQL注入呢?
一般来说mysql自带的过滤函数是比较可靠的。mysql_real_escape_string()
但是这个函数在某些字符集中有问题,比如GBK。如果你用UTF8那没关系。
在PHP里设置数据库的字符集不应该用:mysql_query("SET NAMES UTF8");
而应该用:mysql_set_charset()
这样mysql_real_escape_string()在处理GBK编码的时候就不会出问题了。
mysql_real_escape_string() not safe when SET NAMES is used
use mysql_set_charset() instead.
Note: This is the preferred way to change the charset. Using mysql_query() to execute SET NAMES .. is not recommended.
SET NAMES is usually used to switch the encoding from what is default to what the application needs. This is done in a way that mysql_real_escape_string doesn’t know about this. This means if you switch to some multi byte encoding that allows backslash as 2nd 3rd 4th… byte you run into trouble, because mysql_real_escape_string doesn’t escape correctly. UTF-8 is safe…
Safe way to change encoding is mysql_set_charset, but that is only available in new PHP versions
相关文档:
2200的路过。。PHP本身是简单,但学PHP不是指你走PHP这条路,而是指你走WEB这条路,会PHP,还要会ECSHOP,DZ,PHPCMS,帝国CMS各大程序,你会了么?好,你说你PHP很好,这些我都会,那AJAX?可以灵活运用?AJAX也会,那好,FLEX你会了么?都会,好,你可以自行在WIN2003或者LINUX下配置PHP环境,获取最优环境了么?若想高工资, ......
很久都没有写一下学习日志了,都不知道最近在忙什么,突然觉得自己应该写点什么上去.
数据库的原子操作是两三个月前学的东西了,今天突然又用到了,因此今天必须得将其记录下来,否则下次又要重新搜索了.
原子操作常用的方法就是通过数据回滚来实现,用 PHP 来实现数据库回滚 ......
<?php
function toFixLen($str,$len){ //固定长度字符串的截取
if($len>=strlen($str)||!$len) return $str;
$len-=3;
  ......
PHP 版本各异,已经停止升级开发的有 4.0 系列的 4.4.x,但现在还有部分生产环境在跑这个版本,需要继续维护代码。PHP 5.0 系列是现在开发和应用的主流版本,有 5.1.x 和 5.2.x 系列。PHP 6.0 目前还是试用版本,用 PHP 开发软件产品的人现在可以预先作兼容性测试。
PHP 支持的数据 ......