I am new to iphone development. I am testing passing username from:
iphone/obj-c -> php -> Database/MySql -> php -> return to iphone
I have problem when I pass the username. Here is the code:
NSString *hostStr =[NSString stringWithFormat:@"localhost/username.php?username=%@", tf_username.text];
NSData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]];
NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSUTF8StringEncoding];
NSLog(@"Server output: %@", serverOutput);
my php file(username.php)
<?php
// for testing, i simply output what i received
if(!empty($_GET['username'])){
echo $_GET['username'];
} else {
echo "No parameters";
}
?>
Here is the result when I enter:
Enter I Result
=============================================
test I Server Output: test
test test I Server Output:
When I have a 'space', it will return blank. In php there is this URLEncode, must I encode the string in obj-c first?
What are the security flaws of my methods? (i know there are lots)
Is there any better approach/methods, when get data from web server database? (like my method is: obj-c -> php -> obj-c)
Thanks