2013-02-04 3 views
0

iPad 앱을 통해 온라인으로 액세스하는 MySQL DB에 일부 값을 입력하려고합니다.온라인 데이터베이스에 데이터 삽입

은 데이터를 보냅니다

if(txtInput != nil){ 
     NSString *postVars = [NSString stringWithFormat:@"id=%d&input=%@", index, txtInput.text]; 
     NSLog(@"%d",index); 
     index++; 
     NSData *data = [postVars dataUsingEncoding:NSUTF8StringEncoding]; 

     NSString *strURL = @"http://localhost:8888/Insert.php"; 
     NSURL *url = [NSURL URLWithString:strURL]; 
     NSMutableURLRequest *req = [[NSMutableURLRequest alloc]initWithURL:url]; 
     [req setHTTPBody:data]; 
     [req setHTTPMethod:@"POST"]; 
     NSURLConnection *con = [NSURLConnection connectionWithRequest:req delegate:self]; 
    } 

웹 서비스에 대한 스크립트 : 나는 PHPAdmin 페이지에서 내 응용 프로그램을 실행하면

<?php 
$host = 'localhost'; 
$username = 'root'; 
$password = 'root'; 

$con = mysql_connect($host, $username, $password); 
if(!$con) 
{ 
echo "Failed connection"; 
echo "<br/>"; 
die('Connection failed'); 
} 

mysql_select_db("unbounded", $con); 

$ids = $_GET['id']; 
$str = $_GET['input']; 

$in= mysql_query("INSERT INTO `unbounded`.`stuff` (`id`, `string`) VALUES ('$ids','$str');"); 
echo $in; 
echo "<br/>"; 
mysql_close($con); 
?> 

내가 그 id 값이 0 때마다로 설정되어 볼 수 있습니다 I 문자열 값이 비어있는 동안 앱을 실행하십시오.

브라우저를 통해 스크립트를 실행하면 데이터를 잘 삽입 할 수 있습니다. 그런데 일단 스크립트 vi 브라우저를 실행하면 DB와의 연결이 잘 이루어 졌음을 발견했습니다. . 문제의 원인은 무엇입니까? 최고의 regrads 당신의 아이폰 OS에서

답변

1

모두를 사용하는 경우 그것은 작동합니다

$ids = $_GET['id']; 

을 GET

[req setHTTPMethod:@"POST"]; 

그러나

는 PHP에 당신이에서 읽고있는 데이터를 전송하는 POST 방법을 사용되는 앱 동일한 HTTP 메소드

귀하의 질문과 관련이 없지만 귀하의 PHP 코드는 에 취약합니다. SQL 주입 공격.

+0

그리고 당신은 아주 옳습니다. 고마워! – uml

관련 문제