douzhang3898 2016-02-05 07:45
浏览 726
已采纳

如何阻止用户从浏览器控制台更改脚本[关闭]

Hi i want to stop user changing my scripts from console of browser.

For example: In html,if i have div like below

<div id="demo">
Hi..
</div>

and jQuery

$('#demo').hide();

But still user can do inspect element of this page and they change script or coding from console and they can view the div which has ID demo.So please tell me how to stop user changing my code or even though if they change it should not show the div.

  • 写回答

3条回答 默认 最新

  • doutang7383 2016-02-05 07:54
    关注

    Here you could read an article with some useful words: How to hide a JS Code

    Also, you could use an obfuscation

    You just need to realise that you can't hide a JS code from user, because browser should download it and execute. If you want to encrypt it you should send a pass to browser which user'll get too.

    Just imagine: I'm telling you 1 and you should tell me the same. What would you tell me if I'd told you 2 ?

    And ... here it is ... problem of all programmers. All programmers want hide their own code : ). Just ... believe me. It is.

    One more suggestion is just to try this: Online Obfuscator

    If you want to do this with a PHP code, try this:

    // action.php
    <?php 
    
    if ( !isset($_POST['show']) ) {
        die('HACKER !');
    } else {
        echo '
        <html>
        <head>
        <title>Main Page</title>
        <body>
        <div id="demo">DEMO</div>
        <br>
        <form action="action.php">
        <input name="show" style="display: none;">
        <input type="submit" value="Try me !"/>
        </form>
        </body>
        </html>';
    }
    ?>
    

    These files should be in same folder.

    // index.html
    <html>
    <head>
    <title>Main Page</title>
    </head>
    <body>
    <form action="action.php">
    <input name="show" style="display: none;">
    <input type="submit" value="Try me !"/>
    </form>
    </body>
    </html>
    

    Good luck : )

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵