Please bear with me if this sounds a bit ridiculous, but I've only just learned the basics of PHP and jQuery over the last week or two. This might be plainly obvious to anyone with a modicum of experience, so I appreciate any information you can share.
I'm updating my website to include a custom search function that queries a SQL database through a cURL call. In short:
I take user input from an HTML form (including a text box), then POST the values to a php file (searchfunction.php) on my server under my domain.
searchfunction.php then processes the form data, adds it to a URL query string that includes a private API key (in the format of http://apidomain/[api key]/request.php?querystring), and sends that off to a 3rd-party server via a curl_init.
The 3rd-party server then returns a serialized php array based on the URL's query string. The php file then processes the array and echoes some HTML that appears on the same page as the original user form (via some jQuery magic that I only barely understand).
Here are my questions:
Q1) Because I'm sending a cURL string to an API which then handles all the SQL stuff, am I at any risk of a SQL injection? If so, what is the theory behind eliminating that risk?
Q2) How can I keep the private API key hidden? The browser URL bar will never contain it, but is there a simple way - maybe through the .htaccess file - to keep prying eyes away from the content of the php file that processes the form data and returns the HTML?
Q3) Are there any other obvious security loopholes that I should be aware of? There are ways to write to the database through the API (though not without the API key and the appropriate query string syntax), so how can I prevent a malicious user from manipulating the cURL call?
Thanks for your help in advance. Now that I've stepped into the bewildering world of making my website talk to other servers, I've found myself completely in over my head, especially when it comes to security.