这种方法有多安全?

时间:2014-06-17 12:18:19

标签: php mysql ios security webserver

我想从iphone设备上的MySql数据库中选择数据。我认为最简单的方法是使用GET参数连接到php文件,然后将其作为字符串返回。

现在我只是想知道有人会找到IP地址和文件的机会,并从应用程序以外的其他地方使用它。

1 个答案:

答案 0 :(得分:1)

1-使用基本的http身份验证请求,如:

curl -u username:password http://yourWebPage

2-然后使用基本的http auth响应,如:

$username = $_SERVER['PHP_AUTH_USER'];
$password = $_SERVER['PHP_AUTH_PW'];

if($username == $correctUsername AND $password == $correctPassword){
   //do some thing 
}else{
  header('WWW-Authenticate: Basic realm="My Realm"');
  header('HTTP/1.0 401 Unauthorized');
  die ("Not authorized");
}

3-然后将您的数据发送到http post的正文中作为json string

4-在php文件中接收发布的数据:

$myData = json_decode(file_get_contents('php://input'));