0

我有一个使用 ssl 的安全站点。我有一个用于检查登录的 php 文件,如果您没有登录,它会显示一个登录表单,一旦您登录页面刷新并再次检查登录,当它通过时它会加载页面内容。我想要做的是让它在 https 中加载登录,然后当 javascript 从 ajax 获得登录成功的 ok 时,页面仅使用 http 重新加载以减少页面的加载时间和延迟(这些很大页面和任何小事都会有所帮助)。我需要动态地执行此操作,所以我不能只给它一个重定向 url。

4

2 回答 2

1

要解决此问题,您可以使用在您需要登录的每个页面顶部加载的未经测试的伪代码。

if(loggedin()&&$_SERVER[SERVER_PORT]==443)
{ 
   //if user is logged in but they are still on the https site, redirect to the http site
    header("Location:http://$_SERVER[HTTP_HOST]$_SERVER[SCRIPT_NAME]?$_SERVER[QUERY_STRING]");
}
elseif(!loggedin()&&$_SERVER[SERVER_PORT]!=443)
{
    //if the user is not logged in and they are not on the secure site,  send them to the login page on the secure site
    header("Location:https://$_SERVER[HTTP_HOST]/login.php");
}
于 2012-06-03T04:29:43.563 回答
0

.htaccess 使用是推荐的方法。使用 .htaccess 仅对单个页面或特定页面使用 https。

检查更多 http://www.sitepoint.com/forums/showthread.php?694107-htaccess-rule-redirect-https-for-just-one-page

HTTPS 仅在带有 .htaccess 的特定页面上

于 2012-06-03T05:06:52.493 回答