使用PHP检查页面是否通过SSL访问 [英] Use PHP to check if page was accessed with SSL
本文介绍了使用PHP检查页面是否通过SSL访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以检查当前页面是否已使用SSL打开?例如,我希望我的登录页面(login.php)检查是否使用SSL(https://mywebserver.com/login.php)访问了该页面.如果没有,请将其重定向到页面的SSL版本.
Is there a way to check if the current page was opened with SSL? For example, I want my login page (login.php) to check if it was accessed using SSL (https://mywebserver.com/login.php). If not, redirect them to the SSL version of the page.
非常,我想确保用户安全地使用页面.
Pretty much, I want to enfore that the user uses the page securely.
推荐答案
您应该能够检查是否已设置$_SERVER['HTTPS']
,例如:
You should be able to check that $_SERVER['HTTPS']
is set, e.g.:
if (empty($_SERVER['HTTPS'])) {
header('Location: https://mywebserver.com/login.php');
exit;
}
这篇关于使用PHP检查页面是否通过SSL访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文