Redirect if not referred from specific page

Here’s the scoop:
I don’t want anyone adjusting the id url parameters and accessing pages they shouldn’t be seeing.

So basically…how do I make it so details.php is ONLY accessible by clicking a link from the master.php page? I don’t want anyone to be able to access it by typing in the url, and I don’t want it to be clickable through any other link other than master.php thats on my site. If it’s hotlinked or directly accessed, I want to redirect them to index.php

Is there a php solution? Or an .htaccess solution? I have no idea how to do this and it’s driving me nuts! Please help!