I am building a sample server so that I can learn PHP and was wondering if this is a good way to secure my database. Essentially I am sending my own API key. Is this even doing anything useful, or would this be easy to overcome.
If this is horrible, what is the standard way to approach this?
Below is the php file
<?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);
}
?>
The web request looks like (from an iOS app);
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];
}