You can use PHP and sessions() to keep your JavaScript code secure... check out the following files (my test files) to see how it's done.
PHP PAGE (set-up your session variable)
Code: Select all
<?
session_start();
if(!session_is_registered('access'))
{
session_register('access');
$access = true;
}
?>
<html>
<head>
<script language="JavaScript" src="SCRIPT.php"></script>
</head>
</html>JAVASCRIPT FILE aka SCRIPT.php
Code: Select all
<?
session_start();
if($access)
{
header("Content-type: text/javascript");
?>
//any javascript can go in here
alert("woohoo it works at last!");
<?
$access = false;
}
?>Now when the main page runs it will load the javascript file as it should.. however, when someone tries to access the script.php file directly in order to try and steal your code they won't be able to because it will just spit out a blank page.
I'm happy now
Hope it comes in useful for someone else.
PS. You may need to re-jig the code a little bit if your server doesn't allow global_variables to be used.