iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (34)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

May 12, 2008
Film Makers, Bands and Comedians Welcome on MySpace
About
 
May 12, 2008
Software Engineering for Ajax
WebReference.com
 
May 12, 2008
What is the Head Tag For?
About
 
May 11, 2008
Improving accessibility for motor impaired users
WebDevTips UK
 
May 11, 2008
10 ways to orientate users on your site
WebDevTips UK
 
May 11, 2008
Web Design Clinic - Rros restoration camp 2006
About
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /JavaScript

How To Hide Your JavaScript With PHP! 

  Views:    7649
  Votes:    8
by Ben Sinclair 11/29/03 Rating: 

Synopsis:

Don't want your JavaScript copied? Here's a very simple script that will hide it!
Pages: 
The Article

I hate the thought of JavaScript that you don't want to be copied being copied... Here's a little script that will hide it so that no one can copy it!

The Script

On the page where the JavaScript is placed, add:

<?
session_start();
if(!session_is_registered('allow_script'))
{
session_register('allow_script');
$allow_script = true;
}
?>
<html>
<head>
<script language="JavaScript" src="script.php"></script>
</head>
<body>
Body goes here...
</body>
</html> 
 

And now create a new file called script.php and place your JavaScript there:

<?
session_start();
if($allow_script)
{
header("Content-type: text/javascript");
?>

alert("Woohoo! My JavaScript Works!");

<?
$allow_script = false;
}
?>
 
 

As you can see it uses a session. When you open the page where the JavaScript is placed it creates a session which allows the JavaScript to be viewed. But if you open script.php by its self, no session is created!

Try opening script.php in your browser window and you'll notice you can't view the code!

Enjoy!

Pages: 

Similar/related articles:


 
  Sponsors