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环境,获取最优环境了么?若想高工资, ......
老廖曾经在PHPER杂志上发表过一篇文章叫做用VIM做PHP开发环境,在里面详细介绍了用VIM做php开发需要做的准备,这篇文章就结合一些资料和我自己的一些经验来介绍下用VIM做C/C++开发需要做的事情,相对来说要比做php开发方便些。
前提条件是当然是你已经下载了VIM,如果没有的话请先到官方网站下载最新版本,地址是:http:/ ......
<?php
function remove_directory($dir) {
if ($handle = opendir("$dir")) {
while (false !== ($item = readdir($handle))) {
if ($item != "." && $item != "..") {
......
php文件
<?php
mysql_connect("localhost","","");
mysql_query("set names 'gb2312'");
mysql_select_db("shop");
$sqlstr="select * from goods";
require 'smarty/libs/Smarty.class.php';
$smarty = new Smarty;//设置各个目录的路径,这里是安装的重点
$smarty->template_dir ="smarty/templates/templa ......