How can I detect if my php script is being called from another domain and the other domain is making illegal use of my script? Is there a way to prevent this too?
This isn't a problem that can be solved. If you create a website you make it, by definition, openly available.
If you want your data to be private, you need to require some sort of login.
It is impossible to create a system that is open to users but not to scripts without login/annoying captchas.