Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: how protect external javascript using PHP

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

    Default

    Try
    PHP Code:
    <?php
    error_reporting
    (E_ALL);
     
    ini_set("display_errors"1);
    echo 
    "start<br />";
    if (
    defined('IN_SITE')) {
    echo 
    "in site";
    echo 
    "$_GET['type']";
        
    $sPath '';
        switch(
    $_GET['type']) {
            case 
    'css':
    echo 
    "in css";            
    header('Content-type: text/css');
                
    $sPath "Excss/$_GET['serve'].css";
                break;
            case 
    'js':
    echo 
    "in js";
                
    header('Content-type: text/js');
                
    $sPath "Exjs/$_GET['serve'].js";
                break;
        }
    echo 
    "out of case $sPath was set?";   
     
    // sPath should be a non-published directory
        
    $fp file_get_contents($sPath);
        if (
    $fp) {
           echo 
    $fp
        }
    }
    ?>
    Post back any error message or what the output is.
    Corrections to my coding/thoughts welcome.

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

    Default

    via this code no out put at all(no error message).
    other parts are working.it seems to be, there is no css & no JavaScript.

  3. #13
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    are you trying to prevent hotlinking (other sites linking directly to your files, on your server, for their own use) to your javascript/css?

    >> you can prevent hotlinking using .htaccess

    or, do you want to prevent people from being able to see/copy your javascript/css?

    >> that's impossible.

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

    Default

    try this,
    PHP Code:
    <html>
    <head>
    <title>Test</title>

    <?php

    session_start
    ();
    $_SESSION['insite'] = true;

    function 
    quitInsite()
    {
        unset(
    $_SESSION['insite']);
    }

    if (!
    defined('SHUTDOWN_REGISTERED')) // *_once, this shouldn't be necessary
    {
        
    register_shutdown_function('quitInsite');
        
    define('SHUTDOWN_REGISTERED'true);
    }

    ?> 

    <link rel="stylesheet" type="text/css" href="hide.php?type=css&serve=css_test"/>  

    <script type="text/javascript" src="hide.php?type=css&serve=js_test">  

    </head>
    <body>
    </body>
    </html>

    PHP Code:
    <?php
    session_start
    ();

    if (isset(
    $_SESSION['insite']))
    {
        
    $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);
        }
    }

    ?>

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

    Default

    thanx for help me.
    it is not working again. should it be with session! however it is not working dear!

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
  •