我正在尝试转义 php 上的无效字符。同时还尝试名为 ezsql 的 php 类。 这是我的代码:
<?php
include_once('ez_sql_core.php');
include_once('ez_sql_mysql.php');
$db = new ezSQL_mysql('root','pword','db','localhost');
$uname=$db->escape($_GET['uname']);
$pword=$db->escape($_GET['pword']);
$db->query("INSERT INTO users(Uname, Hpword) VALUES('$uname','$pword')");
?>
如何避免生成这样的 url。而不是搞乱整个查询。 http://localhost/folder/file.php?uname=uzer 's^&*%#&pword=dd'$#$%#'s
最佳答案
通常,您会使用 mysql_real_escape_string()功能:
$uname=mysql_real_escape_string($_GET['uname']);
$pword=mysql_real_escape_string($_GET['pword']);
但由于转义是您使用的框架的一部分,您的代码中已经包含了:
$uname=$db->escape($_GET['uname']);
$pword=$db->escape($_GET['pword']);
我猜想,这些行就可以了,所以不需要其他任何东西。
关于php函数清除通过url传递的用户名和密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5448729/