歡迎來到Stackoverflow。
爲了達到你想要做什麼,你需要從應用程序的用戶名+密碼張貼到您的服務器上的腳本,運行SQL查詢到的數據返回到應用程序。 Theres是一個易於使用的Library ASIHTTPRequest(http://allseeing-i.com/ASIHTTPRequest/How-to-use),它可以幫助您建立網絡。一個例子下面..
實施例請求:
NSURL *url = [NSURL URLWithString:@"http://yourscript.php"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"user1" forKey:@"username"];
[request setPostValue:@"pass1" forKey:@"password"];
[request setDelegate:self];
[request startAsynchronous];
實施例響應:
- (void)requestFinished:(ASIHTTPRequest *)request {
NSString *responseString = [request responseString];
NSLog(@"%@",responseString);
}
在PHP腳本:
$user = $_POST['username'];
$pass = $_POST['password'];
$sql="SELECT * FROM users where username='$user' and password='$pass'";
print_r($sql); //Sends response back to the App to requestFinished: method.
這些只是簡短的例子,當然你應該考慮考慮mysql注入和錯誤檢查。希望這可以幫助。
你真的應該要求HTTPS而不是http連接,並且散列密碼而不是直接發送它。請參閱:http://dustwell.com/how-to-handle-passwords.html – EricS
正如我所說的,這只是一個'最簡單的基本形式'的例子,以便給出一個'想法'如何去做吧,沒有安全感。 – skram