Preventing your game from running on unknown servers
After all the hard work you've had to go through to complete your web game project, it wouldn't be fair if it ended up generating traffic and income on someone else's website. In this recipe, we will create a script that prevents the main game menu from showing up unless it's hosted by an authorized Server.
Getting ready
For this recipe, you will need access to a webspace provider where you can host the game. However, you can test locally using a localhost web Server, such as the built-in PHP one, or an AMP Apache or Nginx web server.
You also will need to have installed the Unity WebGL build target.
NOTE: At the time of writing (summer 2018), for macOS computers, there is still an issue adding the WebGL package if it is not included at the time of original installation via Unity Hub. The macOS WebGL package requires the Unity application to be in the Applications | Unity folder. When installed via Unity Hub, it is actually in Applications...