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
相关文档:
<?php
/*
图片处理函数功能:缩放、剪切、相框、水印、锐化、旋转、翻转、透明度、反色
处理并保存历史记录的思路:当有图片有改动时自动生成一张新图片,命名方式可以考虑在原图片的基础上加上步骤,例如:图片名称+__第几步
*/
class picture{
var $PICTURE_URL;//要处理的图片
var $DEST_URL="temp__01.jpg" ......
将一个1维数组分割成2维数组 array_chunk()
$input_array = array('a', 'b', 'c', 'd', 'e');
print_r(array_chunk($input_array, 2));
比较2个数组,array_diff_assoc()或者array_diff(),如果返回值为空,表示两个数组相同,否则就不同。
用一个函数来过滤数组中的数值array_filter()
functi ......
软件离不开数据库,而PHP最常用的数据库是MySQL。MySQL数据库分服务端和客户端。
MySQL服务端的安装:
(1)点击MySQL安装包(此处的安装程序为mysql-5.0.18-win32.zip)
(2) 默认是Typical,如果想修改安装路径的话也可以选择custom.
注意:安装mysql的路径中,不能含有中文!
(3)点击intall开始安装
(4)跳过注册
(5 ......
PHP是一门开发速度快,运行速度快的语言,但是它也有致命缺点,无多线程(虽然Apache的服务器在另一种程度上弥补了这种缺陷,但是在编写一些需要高并发并且考虑效率的程序下,它还是明显不足)。
但是PHP可以大大缩短开发周期,与开发成本(比如PHP对于程序要求的门槛很低)。
总体来说,PHP很适合开发网站来用,而在开发 ......