I have a php script called from html tag, as
<script src="js/myscript.php"> </script>
Please help me finding a php function to detect if this script is called directly or from script tag of my website.
I wish to prevent someone pasting link to address bar and getting content of myscript.php, as
http://www.mysite.com/js/myscript.php
If you are using javascript, you CANNOT prevent everyone being able to see it. You can't expect a browser to be able to do what the script tells it to do without telling it what to do :)
Your file ext is a PHP, but it is in a js folder. If the output is only JS, you can't stop people being able to view it in any real reliable manner.
Not much you can do here other then check the $_SERVER['HTTP_REFERER'], which by no means is a secure way of doing this. Its pretty much impossible to do what your asking as there are simple ways around this.
Your best bet would be to obfuscate the code which would make it harder to read should they load the URL, but again, there are ways around this also.