从客户端隐藏JavaScript代码

这是向客户端完全隐藏JavaScript代码的唯一工作方式,就像PHP或ASP代码一样。

在这里,我们需要PHP的帮助。 这是代码:

index.php

__________________________________________________ ______

<?PHP
    @session_start(); //Start our session.
    if(@!session_is_registered('PrintTheJavaScript')){ //If the session is not registered (and it's not).
        @session_register('PrintTheJavaScript'); //Register the session.
    } // End if(@!session_is_registered('Pri...
    $_SESSION["PrintTheJavaScript"] = true; //Set the session value to TRUE.
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256" />
<title>Hide Javascript Code</title>
<!--Here we call our Javascript page the first time it'll provide us with our javascript code -->
<script language="javascript" src="./javascript.php"></script>
<!--
We call the same page again AND THIS IS SECOND PART OF THE TRICK.
because after we called it the first time it will set the session value to FALSE which mean it will print NOTHING
-->
<script language="javascript" src="./javascript.php"></script>
</head>
    Try to save this page or go straight from your browser to the (javascript.php) page<br>
    and see if you can get my javascript code.<br>
    YOU'LL NEVER CAN.
<body>
</body>
</html>
__________________________________________________ ___________

javascript.php

__________________________________________________ ___________

<?php
/*
     ___________________________________________________________
    |                                                                                                        |
    |    Script name: Hide Javascript Code.                                                        |
    |    Script date: 16/12/2007                                                                    |
    |    Script author: Mahr Bakr                                                                        |
    |                        admin@SOLAV.com                                                        |
    |    Script goal: Hiding the javascript code from the client like PHP & ASP        |
    |    Script license: Free for personal and commercial.                                    |
    |    *******************************************************    |
    |    Keep this note or at least point to me as the author of the script            |
    |    *******************************************************    |
    /___________________________________________________________\ 
*/
    @session_start(); //Start our session.
    header("Cache-Control: no-store, no-cache"); //Tell the browser to not cache this page (don't store it in the internet temp folder).
    header("Content-type: text/javascript"); //Let the browser think that this is a Javascript page.
    //If the session value is TRUE that means the client has opened the main page (which creates our session and sets its value to TRUE).
    if ($_SESSION["PrintTheJavaScript"] == true){
        //Now we can print our javascript code using PHP's echo command.
        echo '
        // Here is our hidden javascript source.
        var Something="This is a real hidden Javascript code";
        alert(Something);
        // End of our hidden javascript source.
        ';
    }else{
        //If the client tried to open the page straight from the browser (he is trying to see our hidden code).
        // Print some fake code or don't print anything.
    }
    //Set the session value to false AND THIS IS FIRST PART OF THE TRICK.
    //because we are going to call this page again and it'll print nothing (because $_SESSION["PrintTheJavaScript"] <> TRUE)
    //so even if the client tried to SAVE the page this page will be saved empty.
    $_SESSION["PrintTheJavaScript"] = false;
?>
看看是否可以获得我JavaScript代码。 您将永远无法做到。 希望对您有帮助。

From: https://bytes.com/topic/javascript/insights/749685-hide-javascript-code-client

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值