回答
你应该通过你的GET
参数,像这样:
script.php?variable[]=happy&variable[]=sad
在脚本中,这些将被存储在$_GET[variable]
作为数组:
Array ( [0] => happy [1] => sad )
然后,您可以绑定参数和发送声明(未经测试):
<?php
$link = mysqli_connect('localhost', 'my_user', 'my_password', 'world');
/* check connection */
if (!$link) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$type = '';
$query = 'SELECT column FROM bubbles WHERE variable IN (';
for($i = 0; $i < count($_GET[variable]); $i++) {
$query .= '?';
$type .= 's';
if($i+1 < count($_GET[variable])) $query .= ', ';
}
$query .= ')';
$stmt = mysqli_prepare($link, $query);
call_user_func_array('mysqli_stmt_bind_param', array_merge(array($stmt, $type), $_GET[variable]));
/* execute prepared statement */
mysqli_stmt_execute($stmt);
/* close connection */
mysqli_close($link);
?>
+1:我希望我可以两次投票,因为这既是一个坚实的答案,也隐含地解决了注射问题。 – 2013-02-09 15:40:30
请...永远不要使用未加引号的数组键。它依赖于一个可怕的PHP错误特性(字符串化未定义的常量)并在每次执行时产生一个E_NOTICE。 – ThiefMaster 2013-02-09 20:21:31
谢谢非常 – 2013-02-11 11:05:29
- 1. .htaccess和php GET
- 2. Http Get和PHP
- 3. PHP形式,做GET和POST
- 4. 逃逸PHP GET和POST值
- 5. PHP需要和包括GET
- 6. PHP:滥用POST和GET
- 7. OOP PHP和“GET-设置”
- 8. PHP GET和加载一个div
- 9. PHP GET菜单
- 10. PHP GET不工作
- 11. GET和POST在PDO
- 12. SQL表格格式的Get-ADGroup和Get-ADGroupMember
- 13. 如何在PHP中为XSS和SQL注入清除POST和GET vars
- 14. curl -GET和-X GET
- 15. php isset($ _ GET ['post_id'])问题
- 16. PHP get image src
- 17. PHP GET +符号?
- 18. PHP GET指数
- 19. PHP GET安全
- 20. PHP Curl GET&POST
- 21. php sql和类
- 22. GET和XMLHttpRequest
- 23. PHP GET和POST数据与fsockopen
- 24. 使用ajax GET方法和php
- 25. PHP的GET和数组生成?
- 26. 让PHP自我和GET变量
- 27. 在PHP中区分GET POST和POST
- 28. 使用PHP GET和POST在Android编程
- 29. 隐藏POST/GET请求 - 闪存和PHP
- 30. php,jQuery,Lightbox,Ajax GET和POST问题
您可以将值作为数组发送,?value [] =变量和值[] =变量2(正确urlencoded ofcourse) – hank 2013-02-09 14:36:59
我认为你不知道SQL注入是如何工作,但是它不会做任何伤害 – 2013-02-09 14:39:36
感谢您的快速回复。如果有人知道一种不太容易的方法,那更是一个问题。汉克 - 不幸的是,这种方法不能用我现有的代码没有大规模的重写。 – 2013-02-09 14:39:47