什么是 https 和 SSL? 它们如何工作? 如何在 PHP 中使用它们?
我知道一般定义,但我需要更多有关如何一般实现它们和具体如何实现 PHP 的详细信息,以及我从中获得的功能到底是什么?
I know the general definition but I need more details on how to implement them in general and PHP in specific, and what exactly are the features I gain from them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SSL 代表“安全套接字层”,它是一种加密 HTTP 通信(除其他外)的方法。 它对网络浏览器和服务器之间的流量进行加密,从而可以发送安全数据而不必担心被窃听。
SSL 是一种 Web 服务器级别的技术,与 PHP 无关。 您可以使用 SSL 启用任何 Web 服务器,无论其上是否有 PHP,并且您无需编写任何特殊的 PHP 代码即可通过 SSL 显示您的 PHP 页面。
互联网上有很多关于如何为您可能使用的网络服务器设置 SSL 的指南。 这是一个广泛的主题。 您可以开始这里是 Apache 的。
SSL stands for "Secure Socket Layer", and it's a method of encrypted HTTP communication (among other things). It encrypts the traffic between a web browser and a server, making it possible to send secure data without fear of eavesdropping.
SSL is a web-server level technology, and has nothing to do with PHP. You can enable any web server with SSL, whether it has PHP on it or not, and you don't have to write any special PHP code in order to make your PHP pages show up over SSL.
There are many, many guides to be found on the internet about how to set up SSL for whatever webserver you might be using. It's a broad subject. You could start here for Apache.
一些网络服务器配置为镜像整个站点,因此您可以通过 http 或 https 获取每个页面,具体取决于您的偏好或网络浏览器如何发送它们。 https 是安全的,但速度有点慢,并且会给您的硬件带来更大的压力。
因此,您可以像往常一样实施您的网站和商店,但决定将从购物车到结账、付款等所有内容都放在 https 下。 为了实现这一点,购物车的所有链接都是绝对链接,并以
https://
为前缀,而不是http://
。 现在,如果人们点击购物车图标,他们就会被转移到安全版本,并且因为从那里开始的所有链接又都是相对的,所以他们会停留在那里。但! 他们可能会手动将 https 替换为 http,或者使用恶意链接继续使用未加密的版本等。
在这种情况下,您可能需要检查您的脚本是否是通过 https 调用的 (
_SERVER["SERVER_PROTOCOL"]< /code>,据我所知),如果没有则拒绝执行(好的做法)。 或发出到安全站点的重定向。
旁注:https 不再使用 ssl exclusivley,tls(ssl 的后继者,请参阅 rfc2818 )是更现代的
经验法则:用户应该可以选择是否在非关键环境中使用 http 或 https,但被迫在网站的关键部分(登录/购物车)使用 https /付款/...)以防止恶意攻击。
some webservers are configured to mirror the whole site, so you can get every page over http or https, depending on what you prefer, or how the webbrowser sends them around. https is secure, but a bit slower and it puts more strain on your hardware.
so you might implement your site and shop as usual, but decide to put everything from the cart to the checkout, payment and so on under https. to accomplish this, all links to the shopping cart are absolute and prefixed with
https://
instead ofhttp://
. now, if people click on the shopping cart icon, they're transfered to the secure version, and because all links from there on are relative again, they stay there.but! they might replace the https with http manually, or go on the unencrypted version using a malicious link, etc.
in this case, you probably might want to check if your script was called over https (
_SERVER["SERVER_PROTOCOL"]
, afaik), and deny the execution if not (good practice). or issue a redirect to the secure site.on a side note: https is not using ssl exclusivley anymore, tls (the successor to ssl, see rfc2818) is more modern
rule of thumb: users should have the choice if they want http or https in noncritical environments, but forced to use https on the critical parts of your site (login/cart/payment/...) to prevent malicious attacks.