Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

protect javascript files

Options
  • 14-07-2006 1:34pm
    #1
    Closed Accounts Posts: 1,200 ✭✭✭


    I have few javascript files that I don't want people to be able to download them.

    I need some help in protecting the files.
    I have a variable defined in the main include file (php) and if defined then allow the page to be viewed else redirect to error404 page.

    can i query the variable from javascript document to make sure is defined?


Comments

  • Registered Users Posts: 3,594 ✭✭✭forbairt


    Don't think so ...

    Javascript files = files that are stored on the client machine to enable a better user experience ... you don't want them to be able to download them ?

    Is this a case of if they are logged in or not ?? could you just use .htaccess files ?


  • Closed Accounts Posts: 1,200 ✭✭✭louie


    no matter if they are logged in or not, i want those files totally private.

    Is it possible?
    I know the browser might catch them for future references but is there a way to stop that?

    I put too much work in those files and i wouldn't like to see others getting the ideea for nothing. Is not only just basic javascript, is a lot more then that and i need to protect it from competition reasons (business type).


  • Registered Users Posts: 2,157 ✭✭✭Serbian


    You can't really protect JavaScript files reliably. One really basic method that would stop people who don't really know what they are doing is this (this is written from memory so may not work):

    Create all the JavaScript files in PHP like so:

    [php]<?php
    if(eregi ('(www\.)?mysite\.com', $_SERVER)):
    header("Content-type: application/x-javascript");
    ?>
    // JavaScript In Here
    <?php
    endif;
    ?>
    [/php]

    Then, either ModRewrite the files to that any .js files request get written to PHP, or you can just include the files like normal JavaScript files:
    <script type="text/javascript" src="script.php"></script>
    


  • Registered Users Posts: 3,886 ✭✭✭cgarvey


    louie wrote:
    no matter if they are logged in or not, i want those files totally private.

    Is it possible?
    No
    louie wrote:
    I know the browser might catch them for future references but is there a way to stop that?
    No

    Anyone that says otherwise is only offering a method to make it harder. If you want the client to excute Javascript, they have to download it, and you've no way to stop that, or control what they do with it after they download it.

    Others have mentioned ways to control who downloads it, and you might want to look into Javascript Obsfucation as an other means of making it harder.

    .cg


  • Registered Users Posts: 1,452 ✭✭✭tomED


    Don't know if this is something you're looking for but might do the trick for a small investment.

    http://www.protware.com/default.htm


  • Advertisement
  • Closed Accounts Posts: 1,200 ✭✭✭louie


    I was looking at that, but the more i think about it the less i want to do this.
    Just gives visitors a reason to try harder.
    Thanks guys for help but i am giving up on the ideea. Is not worth it.


Advertisement