I run a website that creates digitally generated content for free. My visitors don't need an account to start their downloads either. It works simple enough: the end-user fills in a form, the form sends a request to a PHP-script (an 'API') and the PHP-script returns the result.
?
+---------+ +---------+
| | -----------> | |
|FORM.html| | API.php |
| |<-------------| |
+---------+ +---------+
digital
content
At the moment, the PHP script will send an answer to anything that calls it with right arguments. This makes it easy for other websites to just steal my form and hijack my service. In addition, a skilled enough person could request this 'digital content' through CURL, WGET or any automated script. So, my question is:
Q: How can I make sure that a request has been send from a form on my website before answering?
What I tried so far is adding an extra PHP-file on my server that would 'sign' the request (authenticate.php), before sending it through to the API. That worked, but of course, it only moved the problem to this new file. This script would, hapilly and stupidly, sign everything thrown at it and pass it through to API.php
I have also considered adding extra variables to the form, but this is wouldn't help either. A hacker would only need to identify and copy these variables.
I do not need ultimate security as it's 'only' a drawing. But any check is better then none. What would be sensible?
edit:
I'm mostly concerned with other sites using my API. As the content is free anyway, I'm less concerned with bots or scripts accessing the API. Although it would be nice to prevent that too.