【发布时间】:2013-03-20 16:36:43
【问题描述】:
我正在构建一个示例服务器,以便我可以学习 PHP,并且想知道这是否是保护我的数据库的好方法。本质上,我发送的是我自己的 API 密钥。这是否甚至可以做任何有用的事情,或者这很容易克服。
如果这很可怕,解决这个问题的标准方法是什么?
下面是php文件
<?php
//Check if insert function exists
$apiKey = "6dM7V0n5GqYJLTMibQDf2gA2a94h8hbF";
if(function_exists($_GET['insert']) && ($_GET['key'])==$apiKey) {
$id = $_GET['id'];
$first=$_GET['first'];
$last = $_GET['last'];
//If found, call the function inser with value as a parameter
$_GET['insert']($id,$first,$last);
}
?>
网络请求看起来像(来自 iOS 应用程序);
NSURL*url=[NSURL URLWithString:@"http://localhost/Tutorials/index.php?insert=insert&id=9000&first=YOOOO&last=LOOOO&key=6dM7V0n5GqYJLTMibQDf2gA2a94h8hbF"];
//URL request
NSURLRequest*request=[NSURLRequest requestWithURL:url];
//Set the connection
connection = [NSURLConnection connectionWithRequest:request delegate:self];
if (connection) {
webData=[[NSMutableData alloc]init];
}
【问题讨论】:
-
以上基本上意味着一旦有人嗅探请求甚至从浏览器的历史记录中检索它,他们可能会完全控制。