是否应用CSS display:none或使用if(false){content}阻止客户端内容? [英] Apply CSS display:none or use if(false){content} to block content at clients?
问题描述
方法1 :
使用CSS display:none
表示内容已发送到客户端,但从视图中隐藏.换一种说法;内容确实存在,但不占用任何空间.
方法2 :
使用if(false){content}
可以完全阻止将内容发送到客户端.
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Approaches</title>
</head>
<body>
<div <?php if (true) {echo 'style="display:none;"';}?>>
Approach 1
</div>
<?php if (false): ?>
<div>
Approach 2
</div>
<?php endif; ?>
</body>
</html>
在安全实践方面哪个更好?
如果两者都是安全的,那么从性能和代码设计方法论上看哪个更好?
绝对接近2
如果您不希望客户查看您的内容,那么最好根本不将其发送给他们.
方法1的判决:
- 如果您向他们发送div的内容,即使他们没有在屏幕上显示给他们,他们也可以始终查看您页面的源代码并在那里查看.
方法2的判决:
- 因为内容从一开始就没有发送给他们,所以即使他们查看源也看不到它.
Approach 1:
Using CSS display:none
means that the content is sent to the client but is hidden from view. In other words; the content does exist but without occupying any space.
Approach 2:
Using if(false){content}
prevents the content from being sent to the client at all.
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Approaches</title>
</head>
<body>
<div <?php if (true) {echo 'style="display:none;"';}?>>
Approach 1
</div>
<?php if (false): ?>
<div>
Approach 2
</div>
<?php endif; ?>
</body>
</html>
Which is regarded better in terms of security practices?
If both are secure, then which is regarded better in terms of performance and code design methodology?
Definitely Approach 2
If you don't want the client to view your content, then not sending it to them at all is always better.
Approach 1 verdict:
- If you send them the div's content, then they can always view your page's source and see it there, even though it's not shown to them on screen.
Approach 2 verdict:
- Because the content is never sent to them in the first place, they can't see it even if they view source.
这篇关于是否应用CSS display:none或使用if(false){content}阻止客户端内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!