Oturum PHP HTTPS için HTTP geçerken kayıp
Ödeme sayfası için Kullanıcı gönderirken, http://mysite.com https://mysite.com geçti. Sonuç olarak, $_SESSİON değişkenleri kayboluyor.
Site olabilir veya bazı kullanım olabilir geçerli bir SSL sertifikası vardır.
CEVAP
Aynı server üzerinde HTTP ve HTTPS hizmetler arasında geçiş yaptığınızda, HTTP oturum KİMLİĞİ HTTPS oturumu olarak kabul ediliyor. Üç olası yollardan birinde sayfası: HTTPS HTTP sayfasından oturum KİMLİĞİ geçerek ayarlayabilirsiniz
session_start()bir oturum oluşturur veya geçerli tabanlı özgeçmiş isteği ile geçirilen bu geçerli oturum kimliği gibi GET, POST, veya bir çerez
Oturumları kullanırken, normalde session_start() ile komut başlayacak. Eğer tarayıcı oturumu varsa KİMLİK tanımlama bilgisi, session_start() oturum KİMLİĞİ kullanın. Eğer tarayıcı oturumu var mı yoksa ID cookie set session_start(), yeni bir tane oluşturur.
Eğer oturum KİMLİĞİ(örnek, tarayıcı HTTPS oturumu için yeni bir oturum KİMLİĞİ tanımlama bilgisi oluşturma) ayarlanmışsa, session_id() fonksiyonu kullanarak ayarlayabilirsiniz. session_id() da elverişli bir dize olarak oturum KİMLİĞİNİ döndürür. Bu yüzden
...
$currentSessionID = session_id();
...
$currentSessionID değişken geçerli oturum için eşit ID ayarlar, ve
...
session_id($aSessionID);
...
$aSessionID tarayıcıda sessionıd çerez ayarlar. PHP: session_id
Burada iki komut ile bir örnek. Bir HTTP üzerinden erişilen ve diğer HTTPS üzerinden erişilir. Aynı sunucuda oturum verilerini korumak için olmalıdır.
Senaryo 1(HTTP):
<?php
// This script will create a session and display a link to your secure server address
// to transfer your session ID. In this example, the secure page to receive the session
// ID is located at http://www.yoursite.com/safePages/securePage.php
// Start a session using the current session ID stored in a cookie, or create
// a new session if none is set.
session_start();
$currentSessionID = session_id();
// Set a variable that will be retrieved with the HTTPS script.
$_SESSION['testvariable'] = 'It worked';
// $secureServerDomain is the domain of your secure server
$secureServerDomain = 'www.yoursite.com';
// $securePagePath is the path to the page that will receive and set the session ID.
$securePagePath = '/safePages/securePage.php'
echo '<a href="https://' . $secureServerDomain . $securePagePath . '?session="' . $currentSessionID . '">Click here to transfer your session to the secure server</a>';
?>
Senaryo 2(HTTPS):
<?php
// Retrieve the session ID as passed via the GET method.
$currentSessionID = $_GET['session'];
// Set a cookie for the session ID.
session_id($currentSessionID);
// Start a session.
session_start();
// Test retrieval of variable set when using HTTP.
if (!empty($_SESSION['testvariable'])) {
echo $_SESSION['testvariable'];
} else {
echo 'It did not work.';
}
?>
Bu iş için HTTP ve HTTPS sunucuları aynı oturumu kullanmanız gerekir (varsayılan dosya işleyicisi için, yani, aynı php ile.aynı fiziksel makine üzerinde çalışan veri depolama yüzey ını). Bazı güvenlik açıkları var, bu kod, bir hassas bilgileri aktarmak için kullanmak istiyorum. Sadece uygulanabilir bir örnek olarak tasarlanmıştır.
Bu sorunu daha önce koştu, hızlı bir düzeltme olarak yukarıdaki ile geldim, ama sorunun gerçek nedenini hatırladı. http://www.example.com/page.php 20 ** gidecektim (eksikliği fark "" www. http://www.example.com/page.php https://www.example.com/page.php bağlantı olduğundan emin olun ve http://example.com https://example.com/page.php link.
PS, aslında olduğu gibi düzgün çalışmasını engeller bu bir yazım hatası olabilir bu yüzden bu komut için bir sebep yoktu.

Nasıl kullanıcılar sayfama erişmek içi...
Güvenli HTTP, HTTPS için bir form gönd...
HTTP durum doğru oturum açma sayfası i...
Heroku NodeJS https ssl zorla için htt...
Https için http yeniden yönlendirme kö...