简体   繁体   English

防止显示源代码行

[英]Prevent a line of source code from showing

How to hide this html line, that will not appear for the user in inspect element or view source. 如何隐藏此html行,该行不会在用户在inspect元素或view source中出现。

<input type="hidden" name="kda" value="<?php echo $code;?>">

how can I do this? 我怎样才能做到这一点?

You can't do that - everything you send to the browser can eventually be read and stored somehow. 您无法做到这一点-发送到浏览器的所有内容最终都可以通过某种方式读取和存储。

What you can do instead, however, is using a session to store this information. 但是,您可以使用会话来存储此信息。 Then, only a session identifier will be sent to the browser (and back to the server) while your sensitive information can stay on the server. 然后,只有会话标识符将发送到浏览器(并返回到服务器),而您的敏感信息可以保留在服务器上。

It's impossible to hide HTML from view source. 从视图源隐藏HTML是不可能的。 Any HTML gets sent to the client and can be viewed in view source. 任何HTML都会发送到客户端,并且可以在视图源中进行查看。 Try storing it in $_SESSION , a PHP superglobal. 尝试将其存储在PHP超全局变量$_SESSION It gives the user a cookie that tells PHP where to look to find that user's information in $_SESSION . 它为用户提供了一个cookie,该cookie告诉PHP在$_SESSION查找该用户信息的位置。

$_SESSION is an array. $_SESSION是一个数组。 That means you can store $_SESSION['pies_bought'] = 7 and $_SESSION['cakes_bought'] = 3 . 这意味着您可以存储$_SESSION['pies_bought'] = 7$_SESSION['cakes_bought'] = 3

http://www.php.net/manual/en/session.examples.basic.php http://www.php.net/manual/zh/session.examples.basic.php

If you "hide" it, it won't work. 如果您“隐藏”它,它将不起作用。 You could surround in PHP comment so it's stripped when the server renders the page, but I think you are asking to hide the value of this hidden form field, and that you can not do as you are suggesting. 您可以将PHP注释括起来,以便在服务器呈现页面时将其删除,但是我认为您是在要求隐藏此隐藏表单字段的值,并且您不能按照建议执行操作。 You could post the "viewable" form fields to another php script that then adds this "confidential" key, and then submits the form wherever it's going. 您可以将“可见”表单域发布到另一个php脚本,然后添加此“机密”键,然后将表单提交到任何地方。 You could, upon submission of form, call an ajax request to get the value and submit all at once. 您可以在提交表单后调用ajax请求以获取值并立即提交所有内容。

Many ways to skin a cat. 剥皮猫的方法很多。

将此标志设置为PHP变量,而不是在表单中实际包含hidden输入字段。

You may use encryption if you still want to use it as a query parameter in your form otherwise session is your best bet. 如果您仍想在表单中将其用作查询参数,则可以使用加密,否则会话是最好的选择。

<input type="hidden" name="kda" value="<?php echo some_php_crypt_function($code);?>">

When you receive kda on the server,just decrypt it and get the value. 当您在服务器上收到kda时,只需对其解密并获取值即可。

This link http://www.php.net/manual/en/mcrypt.examples.php has examples of how to use encryption/decryption in php. 此链接http://www.php.net/manual/en/mcrypt.examples.php包含有关如何在php中使用加密/解密的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM