pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

    <i id='Gfnf2'><tr id='Gfnf2'><dt id='Gfnf2'><q id='Gfnf2'><span id='Gfnf2'><b id='Gfnf2'><form id='Gfnf2'><ins id='Gfnf2'></ins><ul id='Gfnf2'></ul><sub id='Gfnf2'></sub></form><legend id='Gfnf2'></legend><bdo id='Gfnf2'><pre id='Gfnf2'><center id='Gfnf2'></center></pre></bdo></b><th id='Gfnf2'></th></span></q></dt></tr></i><div class="vfptzfv" id='Gfnf2'><tfoot id='Gfnf2'></tfoot><dl id='Gfnf2'><fieldset id='Gfnf2'></fieldset></dl></div>
  • <legend id='Gfnf2'><style id='Gfnf2'><dir id='Gfnf2'><q id='Gfnf2'></q></dir></style></legend>
      <bdo id='Gfnf2'></bdo><ul id='Gfnf2'></ul>

      <small id='Gfnf2'></small><noframes id='Gfnf2'>

      1. <tfoot id='Gfnf2'></tfoot>

        PHP session HTTP to HTTPS 問題

        PHP session HTTP to HTTPS problem(PHP session HTTP to HTTPS 問題)
        <legend id='1MLeJ'><style id='1MLeJ'><dir id='1MLeJ'><q id='1MLeJ'></q></dir></style></legend>
          <bdo id='1MLeJ'></bdo><ul id='1MLeJ'></ul>

                <tbody id='1MLeJ'></tbody>

                <small id='1MLeJ'></small><noframes id='1MLeJ'>

                  <tfoot id='1MLeJ'></tfoot>
                  <i id='1MLeJ'><tr id='1MLeJ'><dt id='1MLeJ'><q id='1MLeJ'><span id='1MLeJ'><b id='1MLeJ'><form id='1MLeJ'><ins id='1MLeJ'></ins><ul id='1MLeJ'></ul><sub id='1MLeJ'></sub></form><legend id='1MLeJ'></legend><bdo id='1MLeJ'><pre id='1MLeJ'><center id='1MLeJ'></center></pre></bdo></b><th id='1MLeJ'></th></span></q></dt></tr></i><div class="9h3h35t" id='1MLeJ'><tfoot id='1MLeJ'></tfoot><dl id='1MLeJ'><fieldset id='1MLeJ'></fieldset></dl></div>
                  本文介紹了PHP session HTTP to HTTPS 問題的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一個 (HTTPS) login.php 頁面,它仍然是 HTTPS(即用戶登錄后轉到帳戶儀表板).現在的問題是說用戶在登錄到安全儀表板時點擊了一個非敏感頁面,如(HTTP)about-us.php 頁面,會話不會通過 HTTP 傳輸,因為我有 session.cookie_secure=1,這意味著用戶在 HTTP 頁面上顯示為已注銷.

                  I have a (HTTPS) login.php page which remains HTTPS (ie once user logged in goes to account dashboard). Now the problem is say the user whilst logged on to the secure dashboard clicks onto a non-sensitive page like (HTTP) about-us.php page, the session is not transmitted over HTTP as I have session.cookie_secure=1, meaning the user appears logged out on HTTP pages.

                  但是,當用戶返回儀表板頁面或任何敏感帳戶頁面時,我被告知他仍應登錄(即從 HTTP 返回到 HTTPS)?然而事實并非如此,他似乎也在 HTTPS 連接上注銷了?

                  However when the user goes back to dashboard page or any sensitive account page I have been told he should still be logged in (ie from HTTP back to HTTPS)? However this is not the case and he appears logged out on the HTTPS connection too?

                  我相信我遺漏了導致此問題的某些內容.這是我的代碼:

                  I believe I am missing something which is causing this problem. Here is my code:

                  這是在 login.php 頁面上調用以啟動會話的 PHP 頭文件:

                  This is PHP header file which is called to start session on login.php page:

                  session_start();
                  session_regenerate_id(true); /*avoid session fixation attempt*/
                  
                  /*Create and check how long session has been started (over 5 mins) regenerate id - avoid session hijack*/
                  if(!isset($_SESSION['CREATED'])) 
                  {
                      $_SESSION['CREATED'] = time();/*time created session, ie from login/contact advertiser/email_confirm only ways for new session to start*/
                  } 
                  elseif(time() - $_SESSION['CREATED'] > 300) 
                  {
                      /*session started more than 5 mins(300 secs) ago*/
                      session_regenerate_id(true); /*change session ID for the current session and invalidate old session ID*/
                      $_SESSION['CREATED'] = time(); /*update creation time*/
                  }
                  
                  /*Check if user is logged in*/
                  if(!isset($_SESSION['loggedin']))
                  {
                      $_SESSION['loggedin']=1;/*used to track if user is logged in on pages*/
                  }
                  
                  /*if return false browser supports standard ob_start();*/
                  if(ob_start("ob_gzhandler")){ob_start();}
                  

                  這是每個頁面都需要的 PHP 頭文件,用于檢查會話是否已經啟動:

                  This is PHP header file required on every page to check if session initiated already:

                  session_start(); 
                  
                  $session_errors=0;/* if>0 user not logged in*/
                  
                  /*check if session is already initiated*/
                  if(isset($_SESSION['CREATED'])) 
                  {
                      if(time() - $_SESSION['CREATED'] > 300) 
                      {
                          /*session started more than 5 mins(300 secs) ago*/
                          session_regenerate_id(true); /*change session ID for the current session and invalidate old session ID*/
                          $_SESSION['CREATED'] = time(); /*update creation time*/
                      }
                  }
                  elseif(!isset($_SESSION['CREATED'])){$session_errors++;}/*user not logged in*/
                  
                  /*Check if user is logged in*/
                  if(!isset($_SESSION['loggedin'])){$session_errors++;}/*user not logged in*/
                  
                  if(ob_start("ob_gzhandler")){ob_start();}
                  

                  此外,如果有任何用途,這是在非敏感頁面(例如 about-us.php)上打開 HTTPS 的代碼

                  Also if any use this is the code to turn HTTPS of on non-sensitive pages such as about-us.php

                  if ($_SERVER['SERVER_PORT']!=80)
                  {
                  $url = "http://". $_SERVER['SERVER_NAME'] . ":80".$_SERVER['REQUEST_URI'];
                  header("Location: $url");
                  }
                  

                  我的 php.ini 文件 cookie 設置

                  My php.ini file cookie settings

                  session.cookie_secure=1
                  session.cookie_httponly=1
                  session.use_only_cookies=1
                  session.cookie_lifetime = 0
                  session.save_path = /tmp
                  session.save_handler = files
                  

                  推薦答案

                  已回答以幫助可能偶然發現此問題的人

                  作為 切換時會話丟失的答案PHP 中從 HTTP 到 HTTPS 已經結束,因為您使用的是 session.cookie_secure = 1 包含會話 ID 的 cookie 在連接從 HTTPS 切換到 HTTP 時不會傳輸.在 HTTP 連接時,當您 session_start() 時,PHP 會創建一個新的會話 ID,該 ID 會替換之前的會話 ID.

                  As the the answer at Session lost when switching from HTTP to HTTPS in PHP has concluded, since you are using session.cookie_secure = 1 the cookie that contains the session ID is not transferred when the connection switches from HTTPS to HTTP. At HTTP connection, when you session_start(), PHP creates a new session id, which replaces the previous session id.

                  答案還提出了一個解決方案,使用查詢字符串傳遞會話 id,然后由頁面獲取.這聞起來有安全漏洞的壞處.別忘了我們最初使用 HTTPS 的原因!

                  The answer also suggests a solution, pass the session id using query string, which is then picked up by the page. This smells of bad of security flaw. Don't forget the reason why we used HTTPS in the first place!

                  因此,我建議您的解決方案是將所有 http 請求重定向到 https 對應請求.對站點中的所有內容使用 HTTPS,從 css、圖像到普通的靜態 html 頁面.這實際上是每個認真對待安全性的應用程序都會做的事情.比如使用HTTP訪問github頁面會返回:

                  So the solution I suggest to you is that you redirect all http request to https counterparts. Use HTTPS for everything in your site, from css, images, to mundane static html pages. This is actually something that every application that is serious about security does. For example, visiting github page using HTTP will return:

                  HTTP/1.1 301 Moved Permanently
                  Server: nginx/0.7.67
                  Date: Sun, 08 May 2011 15:43:01 GMT
                  Content-Type: text/html
                  Content-Length: 185
                  Connection: close
                  Location: https://github.com/
                  
                  <html>
                  <head><title>301 Moved Permanently</title></head>
                  <body bgcolor="white">
                  <center><h1>301 Moved Permanently</h1></center>
                  <hr><center>nginx/0.7.67</center>
                  </body>
                  </html>
                  

                  記住您最初使用 HTTPS 的原因,如果您想完全安全,請在所有情況下都使用 HTTPS.

                  Remember why you used HTTPS in the first place, if you want to be totally secure, use HTTPS for everything.

                  檢測請求是否為 HTTPS (見這個問題)在引導.

                  Detect if the request is HTTPS or not (See this question) at bootstrap.

                  如果請求是 HTTP,要么將所有請求重定向到 HTTPS 主頁,或者您可以嘗試解析 $_SERVER['REQUEST_URI'] 并使用 parse_url 將 HTTP 請求重定向到對應的 HTTPS 請求http_build_url.

                  If the request is HTTP, either redirect all requests to HTTPS home page, or you can try parsing $_SERVER['REQUEST_URI'] and redirecting HTTP request to their HTTPS counterpart using parse_url and http_build_url.

                  第二種替代方案

                  如果您真的不想對所有內容都使用 HTTPS,那么請不要在使用 HTTP 訪問的頁面上session_start().當您這樣做時,安全 cookie 將被保留.

                  If you really really don't want to use HTTPS for everything, then don't session_start() on pages that are accessed with HTTP. Secure cookies will be retained when you do this.

                  第三種替代方案

                  另一種解決方案是嘗試通過 IP 地址和用戶代理檢測用戶.這不能保證是準確的,所以我的建議是對所有事情都使用 HTTPS.例如,即使是普通的靜態頁面,Paypal 也始終使用 HTTPS.

                  The other solution is to try and detect the user by IP addresses and user agent. This is not guaranteed to be accurate, so what I suggest is just use HTTPS for everything. Paypal, for example, always use HTTPS even for mundane static pages.

                  這篇關于PHP session HTTP to HTTPS 問題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  MySQLi prepared statement amp; foreach loop(MySQLi準備好的語句amp;foreach 循環)
                  Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個服務器還是從同一用戶獲取記錄?)
                  PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識別登錄信息)
                  mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個參數)
                  Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結果填充變量)
                  MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“localhost的訪問被拒絕)
                    <tbody id='7XFxq'></tbody>
                  <tfoot id='7XFxq'></tfoot>

                    <bdo id='7XFxq'></bdo><ul id='7XFxq'></ul>
                      <i id='7XFxq'><tr id='7XFxq'><dt id='7XFxq'><q id='7XFxq'><span id='7XFxq'><b id='7XFxq'><form id='7XFxq'><ins id='7XFxq'></ins><ul id='7XFxq'></ul><sub id='7XFxq'></sub></form><legend id='7XFxq'></legend><bdo id='7XFxq'><pre id='7XFxq'><center id='7XFxq'></center></pre></bdo></b><th id='7XFxq'></th></span></q></dt></tr></i><div class="zjdnxdt" id='7XFxq'><tfoot id='7XFxq'></tfoot><dl id='7XFxq'><fieldset id='7XFxq'></fieldset></dl></div>

                      <small id='7XFxq'></small><noframes id='7XFxq'>

                          • <legend id='7XFxq'><style id='7XFxq'><dir id='7XFxq'><q id='7XFxq'></q></dir></style></legend>
                          • 主站蜘蛛池模板: 西安中国国际旅行社(西安国旅) | 二维运动混料机,加热型混料机,干粉混料机-南京腾阳干燥设备厂 | 飞飞影视_热门电影在线观看_影视大全 | 冷藏车-东风吸污车-纯电动环卫车-污水净化车-应急特勤保障车-程力专汽厂家-程力专用汽车股份有限公司销售二十一分公司 | 扬尘在线监测系统_工地噪声扬尘检测仪_扬尘监测系统_贝塔射线扬尘监测设备「风途物联网科技」 | 臭氧灭菌箱-油桶加热箱-原料桶加热融化烘箱-南京腾阳干燥设备厂 臭氧发生器_臭氧消毒机 - 【同林品牌 实力厂家】 | 塑料撕碎机_编织袋撕碎机_废纸撕碎机_生活垃圾撕碎机_废铁破碎机_河南鑫世昌机械制造有限公司 | 依维柯自动挡房车,自行式国产改装房车,小型房车价格,中国十大房车品牌_南京拓锐斯特房车 - 南京拓锐斯特房车 | 气动|电动调节阀|球阀|蝶阀-自力式调节阀-上海渠工阀门管道工程有限公司 | 优秀的临床医学知识库,临床知识库,医疗知识库,满足电子病历四级要求,免费试用 | 绿萝净除甲醛|深圳除甲醛公司|测甲醛怎么收费|培训机构|电影院|办公室|车内|室内除甲醛案例|原理|方法|价格立马咨询 | 防爆型气象站_农业气象站_校园气象站_农业四情监测系统「山东万象环境科技有限公司」 | 活性氧化铝|无烟煤滤料|活性氧化铝厂家|锰砂滤料厂家-河南新泰净水材料有限公司 | 联系我们老街华纳娱乐公司官网19989979996(客服) | 六维力传感器_三维力传感器_二维力传感器-南京神源生智能科技有限公司 | 避光流动池-带盖荧光比色皿-生化流动比色皿-宜兴市晶科光学仪器 东莞爱加真空科技有限公司-进口真空镀膜机|真空镀膜设备|Polycold维修厂家 | 新材料分散-高速均质搅拌机-超声波分散混合-上海化烁智能设备有限公司 | 耐热钢-耐磨钢-山东聚金合金钢铸造有限公司 | 干粉砂浆设备-干粉砂浆生产线-干混-石膏-保温砂浆设备生产线-腻子粉设备厂家-国恒机械 | 猎头招聘_深圳猎头公司_知名猎头公司 | 防爆暖风机_防爆电暖器_防爆电暖风机_防爆电热油汀_南阳市中通智能科技集团有限公司 | 专业深孔加工_东莞深孔钻加工_东莞深孔钻_东莞深孔加工_模具深孔钻加工厂-东莞市超耀实业有限公司 | _网名词典_网名大全_qq网名_情侣网名_个性网名 | 篷房|仓储篷房|铝合金篷房|体育篷房|篷房厂家-华烨建筑科技官网 知名电动蝶阀,电动球阀,气动蝶阀,气动球阀生产厂家|价格透明-【固菲阀门官网】 | 圆盘鞋底注塑机_连帮鞋底成型注塑机-温州天钢机械有限公司 | 电伴热系统施工_仪表电伴热保温箱厂家_沃安电伴热管缆工业技术(济南)有限公司 | 天津仓库出租网-天津电商仓库-天津云仓一件代发-【博程云仓】 | 复合土工膜厂家|hdpe防渗土工膜|复合防渗土工布|玻璃纤维|双向塑料土工格栅-安徽路建新材料有限公司 | 蓝牙音频分析仪-多功能-四通道-八通道音频分析仪-东莞市奥普新音频技术有限公司 | 房在线-免费房产管理系统软件-二手房中介房屋房源管理系统软件 | 二手色谱仪器,十万分之一分析天平,蒸发光检测器,电位滴定仪-湖北捷岛科学仪器有限公司 | 广东青藤环境科技有限公司-水质检测 | 衢州装饰公司|装潢公司|办公楼装修|排屋装修|别墅装修-衢州佳盛装饰 | 厦门网站建设_厦门网站设计_小程序开发_网站制作公司【麦格科技】 | 沟盖板_复合沟盖板厂_电力盖板_树脂雨水篦子-淄博拜斯特 | 不锈钢列管式冷凝器,换热器厂家-无锡飞尔诺环境工程有限公司 | 便民信息网_家电维修,家电清洗,开锁换锁,本地家政公司 | 越南专线物流_东莞国际物流_东南亚专线物流_行通物流 | 南京泽朗生物科技有限公司 | lcd条形屏-液晶长条屏-户外广告屏-条形智能显示屏-深圳市条形智能电子有限公司 | 模切之家-专注服务模切行业的B2B平台! |