Sometime we face the problem when we navigate from HTTP URL to HTTPS URL our session lost.

You can manage session between HTTP to HTTPS or HTTPS to HTTP:

1. Transmit session ID between page using GET

2. POST session ID by POST

3. Use files to save sessions

4. Use Cookies for sessions

5. Use database to save session

Below example can be used to transmit using GET….

File : http.php
……………

<?php

session_start();

$sessionID = session_id();

$_SESSION[‘phpsolutions’] = ‘Demo session between HTTP HTTPS’;

echo ‘<a href=”https://www.phpsolutions.co.in/https.php?session=’.$sessionID.'”>Demo session from HTTP to HTTPS</a>’;

?>

File: https.php
……………

<?php

$sessionID = $_GET[‘session’];

session_id($sessionID);

session_start();

if (!empty($_SESSION[‘phpsolutions’])) {
echo $_SESSION[‘phpsolutions’];
} else {
echo ‘Demo session failed’;
}

?>
IE7 : This page contains both secure and nonsecure items

You have to use relative path for all static resource on page like css, js, images, flash etc. to avoid IE message secure and nonsecure items…

IE message

IE message

Well! stay with us….. 🙂

3 Responses to Session lost when switching from HTTP to HTTPS in PHP

  1. Anonymous says:

    Intriguing article. I know I’m just a little late in posting my comment but the article would have been to the and merely the details I’d been searching for. I can’t say that I go along with all you mentioned nevertheless it was emphatically fascinating! BTW…I found your blog by having a Google search. I’m a frequent visitor in your blog all of which will return again soon.

  2. Anonymous says:

    Intriguing article. I am aware I’m a little late in posting my comment however the article were to the purpose and just the information I became seeking. I can’t say that we accept everything you could mentioned nevertheless it was emphatically fascinating! BTW…I found your website by way of a Google search. I’m a frequent visitor for your blog and will return again soon.

  3. Anonymous says:

    Good idea. Can be considered a learned thing, ok!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.