Most third party services that allow you to add something to your website like widgets or analytics, make you copy a script with a public key (or some variation of that) and request the rest from the back-end.
<script>
window.publicKey = 1
</script>
<script src='domain.com/publicWidget'></script>
So you make an account, you set up everything, embed the code, thing appears on your website.
If no information from the client can be trusted, what stops someone from just copying the script on their website ? How do you make sure that only your users can use it ?
Is there a 'safe/secure' way in PHP
to check if a request comes from a domain you trust/allow ?