脚本宝典收集整理的这篇文章主要介绍了php – 仅对登录页面使用https而不是整个网站,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
目前我的主要登录页面是test_index.PHP,其中包括test_header.PHP
if($_SERVER['SERVER_PORT'] != 443) { header("HTTP/1.1 301 Moved PErmanently"); header("Location: https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); exIT(); }
但这使得完整的网站在https
我也读了here,它可以通过.htaccess,所以我从test_header.PHP删除上面的代码片段并在.htaccess文件中添加以下行
<IfModule mod_rewrite.c> RewriteEngine on # 301 redirect to domain to 'www.' RewriteCond %{HTTP_HOST} ^testweb.COM$[NC] rewriterule ^(.*)$http://www.testweb.com/$1 [R=301,L] </IfModule> <FilESMatch test_index.PHP> RewriteEngine on RewriteCond %{HTTPS} !=on RewriteRule .* https://%{SERVER_NamE}%{REQUEST_URI} [R,L] </FilesMatch>
注意:testweb.com只是一个虚构的名称,而不是实际的网站
但仍然完整的网站运行https,请告诉我我在哪里做错了?
编辑
if ($_SERVER['REQUEST_URI'] == '/test_index.PHP') { // only check https on LOGin if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { header("HTTP/1.1 301 Moved Permanently"); header("Location: https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); exit(); } else { die("Sorry,Your website is not secure"); } } elseif (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { // header("HTTP/1.1 301 Moved Permanently"); header("Location: http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); exit(); }
谢谢
if ($_SERVER['REQUEST_URI'] == '/login.PHP') { // only check https on login if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { // do login stuff } else { // redirect to https or simply give an error } } elseif (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') { // redirect to http }
以上是脚本宝典为你收集整理的php – 仅对登录页面使用https而不是整个网站全部内容,希望文章能够帮你解决php – 仅对登录页面使用https而不是整个网站所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。