Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: how protect external javascript using PHP

  1. #1
    Join Date
    Jul 2010
    Posts
    45
    Thanks
    6
    Thanked 4 Times in 2 Posts

    Question how protect external javascript using PHP

    hi,
    • I want to protect my external javascript(and css also) from outside people, who steal my javascript.

    • but this is impossible using client-side language.

    • so can anyone tell me a method to hide external javascript(and css) by using sever-side language???


    thank you

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    You can not as was already stated in the other post.
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    Apr 2010
    Posts
    40
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default

    why ?

  4. #4
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Why cant you or why would you want to?
    Corrections to my coding/thoughts welcome.

  5. #5
    Join Date
    Jul 2010
    Posts
    45
    Thanks
    6
    Thanked 4 Times in 2 Posts

    Default

    bluewalrus, what do you mean "other post" ???

  6. #6
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Corrections to my coding/thoughts welcome.

  7. #7
    Join Date
    Jul 2010
    Posts
    45
    Thanks
    6
    Thanked 4 Times in 2 Posts

    Default

    I found some code. but it' not working
    the code witch i want to protect
    Code:
    <html>
    <head>
    <title>Test</title>
    
    <link rel="stylesheet" type="text/css" href="Excss/css_test.css">   //external css in the folder of Excss
    <script type="text/javascript" src="Exjs/js_test.js" ></script>  //external js in the folder of Excss
    </head>
    <body>
    </body>
    </html>

    then the new code....
    my.html

    Code:
    <html>
    <head>
    <title>Test</title>
    
    <link rel="stylesheet" type="text/css" href="hide.php?type=css&serve=css_test"/>
    <script type="text/javascript" src="hide.php?type=js&serve=js_test"> </script>
    
    </head>
    <body>
    </body>
    </html>
    hide.php
    Code:
    <?php
    if (defined('IN_SITE'))
    {
        $sPath = '';
        switch(@$_GET['type'])
        {
            case 'css':
                header('Content-type: text/css');
                $sPath = 'Excss/' . @$_GET['serve'] . '.css';
                break;
            case 'js':
                header('Content-type: text/js');
                $sPath = 'Exjs/' . @$_GET['serve'] . '.js';
                break;
        }
    
        // sPath should be a non-published directory
        $fp = @fopen($sPath, 'r');
        if ($fp)
        {
            fpassthru($fp);
            fclose($fp);
        }
    }
    
    ?>
    why is this not working? can anyone correct this code.....?

  8. #8
    Join Date
    Jul 2010
    Posts
    45
    Thanks
    6
    Thanked 4 Times in 2 Posts

    Default

    oh dear! oh dear! that post was mine!!!
    since i didn't get a solution, i decide to post it under PHP. so this is not a "other post". that's mine..........
    so bluewalrus, you can help me to solve my problem at-least looking at above code.please....

    thanx.... hope you all will help me.

  9. #9
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    That's not going to hide the code or protect it. The user just needs the variables which are and have to exposed in your code.

    Anyway if you want to do it the way your doing it can you post a link or the directory structure, just note that it is not anymore secure than linking to the regular css file.

    or you could try

    Code:
    <?php
    if (defined('IN_SITE'))
    {
        $sPath = '';
        @switch($_GET['type'])
        {
            case 'css':
                header('Content-type: text/css');
                $sPath = "Excss/$_GET['serve'].css";
                break;
            case 'js':
                header('Content-type: text/js');
                $sPath = "Exjs/$_GET['serve'].js";
                break;
        }
        // sPath should be a non-published directory
        $fp = @file_get_contents($sPath);
        if ($fp) {
           echo $fp; 
        }
    }
    ?>
    Last edited by bluewalrus; 07-26-2010 at 06:23 PM.
    Corrections to my coding/thoughts welcome.

  10. #10
    Join Date
    Jul 2010
    Posts
    45
    Thanks
    6
    Thanked 4 Times in 2 Posts

    Default

    thnax for responding me.
    but it's not working bluewalrus....
    should it be implement a centralized session management???

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •