I have a web site with following functionality: An user comes to www.mysite.com/page.php
. Javascript on that page makes ajax API call to www.mysite.com/api.php
and shows results on the same page www.mysite.com/page.php
I'm afraid of situation where somebody starts to use my api.php on own software, because using www.mysite.com/api.php
costs me a bit money. Therefore I want that only users that have visited the page www.mysite.com/page.php
can get valid results from www.mysite.com/api.php
. There won't be any way for users to log in to my web site.
What would be the right way to do this? I guess I could start a session when an user comes to page.php and then somehow maybe first check on api.php that a session with valid session id exists?