Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent API calls outside a web site

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?

like image 657
Petri Avatar asked Nov 10 '22 22:11

Petri


1 Answers

If you just want the user to visit page.php before using api.php, the session is the way to go.

like image 51
Alex Angelico Avatar answered Nov 14 '22 21:11

Alex Angelico