没有ssl的重新加载页面(https到http)

时间:2012-06-03 04:14:47

标签: javascript jquery

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

2 个答案:

答案 0 :(得分: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");
}

答案 1 :(得分:0)

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

查看此内容以获取更多信息 http://www.sitepoint.com/forums/showthread.php?694107-htaccess-rule-redirect-https-for-just-one-page

HTTPS only on specific page with .htaccess