Session lost when switching from HTTP to HTTPS in PHP


Hits: 4305  

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[‘svnlabs’] = ‘Demo session between HTTP HTTPS’;

echo ‘<a href=”https://www.svnlabs.com/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[‘svnlabs’])) {
echo $_SESSION[‘svnlabs’];
} 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

Well! stay with us….. 🙂

Published by

Sandeep Verma

I’m an Entrepreneur. I’m proud to work as Blogger, LAMP Programmer, Linux Admin, Web Consultant, Cloud Manager, Apps Developer, Searcher. Concentrate > Observe > Imagine > Launch

40 thoughts on “Session lost when switching from HTTP to HTTPS in PHP”

  1. Pingback: S/M
  2. Great beat ! I would like to apprentice even as you amend your site,
    how could i subscribe for a blog site? The account aided me a acceptable deal.

    I have been tiny bit familiar of this your broadcast offered vibrant transparent
    idea

  3. Excellent beat ! I wish to apprentice while you amend your web site, how could i subscribe for a blog website?
    The account aided me a acceptable deal. I had been a
    little bit acquainted of this your broadcast offered bright clear idea

  4. Hello there, I discovered your site by the use of Google at the same time as
    searching for a similar matter, your web site came up,
    it appears great. I’ve bookmarked it in my google bookmarks.

    Hello there, just became aware of your weblog via Google, and found that
    it is truly informative. I’m going to be careful for brussels.

    I will be grateful if you happen to proceed this in future.
    Numerous other people shall be benefited out of your writing.
    Cheers!

  5. Hello There. I found your blog using msn. This is an extremely well written article.
    I will be sure to bookmark it and come back to read more of your useful info.

    Thanks for the post. I’ll definitely return.

  6. Magnificent goods from you, man. I have understand your stuff previous to and
    you are just extremely excellent. I really like what you’ve
    acquired here, certainly like what you are stating
    and the way in which you say it. You make it enjoyable and you still take care of to keep it wise.

    I can’t wait to read much more from you. This is actually a great website.

  7. My spouse and I stumbled over here by a different web address and thought I might check things out.
    I like what I see so now i’m following you. Look forward to going
    over your web page yet again.

  8. Hey there fantastic website! Does running a blog similar to this require a great deal of
    work? I’ve absolutely no knowledge of coding but I was hoping to start my own blog soon. Anyways, should you have any recommendations or techniques for new
    blog owners please share. I know this is off topic nevertheless I just needed to ask.
    Thanks a lot!

  9. Hi, all the time i used to check weblog posts here in the
    early hours in the daylight, for the reason that i love to gain knowledge of more and more.

  10. Very nice post. I just stumbled upon your blog and
    wanted to say that I’ve truly enjoyed browsing your blog posts.
    After all I will be subscribing to your feed and I hope you write again soon!

  11. Woah! I’m really enjoying the template/theme of this website.
    It’s simple, yet effective. A lot of times it’s very hard to get that “perfect balance” between superb usability and appearance.
    I must say you’ve done a excellent job with this.
    In addition, the blog loads super quick for me on Opera. Exceptional Blog!

  12. Do you mind if I quote a couple of your articles as long as I
    provide credit and sources back to your webpage?
    My blog is in the very same area of interest as yours and my visitors would truly benefit
    from a lot of the information you present here. Please let
    me know if this ok with you. Appreciate it!

  13. I am not positive where you’re getting your
    info, but good topic. I needs to spend some time learning
    much more or working out more. Thank you for magnificent information I used to be looking for this info for my mission.

  14. Hey! This is my first comment here so I just wanted
    to give a quick shout out and say I genuinely enjoy reading your posts.

    Can you recommend any other blogs/websites/forums that cover the same
    topics? Thank you!

  15. Wonderful items from you, man. I have keep
    in mind your stuff previous to and you are simply extremely great.
    I actually like what you have got right
    here, certainly like what you’re stating and the way in which through which you say it.
    You’re making it enjoyable and you still take care
    of to keep it sensible. I can’t wait to read much more from you.
    That is really a terrific website.

  16. My partner and I absolutely love your blog and find most of your post’s to be exactly
    what I’m looking for. Does one offer guest writers to write content for you personally?
    I wouldn’t mind composing a post or elaborating on a lot
    of the subjects you write concerning here. Again, awesome website!

  17. Howdy! This is my first visit to your blog! We are a group of volunteers and starting a new
    initiative in a community in the same niche. Your
    blog provided us valuable information to work on. You have done a wonderful job!

  18. You actually make it seem so easy together with your presentation however
    I to find this matter to be actually one thing that I believe I
    might by no means understand. It sort of feels too complex and very broad for
    me. I am taking a look ahead to your next put up, I’ll attempt to get the cling of it!

  19. Hello there I am so delighted I found your
    blog, I really found you by accident, while I was searching on Google
    for something else, Anyways I am here now and would just like to
    say thanks a lot for a marvelous post and a all
    round interesting blog (I also love the theme/design), I don’t have time to read through
    it all at the moment but I have book-marked it and also included your RSS feeds, so
    when I have time I will be back to read more,
    Please do keep up the fantastic b.

  20. Heya i am for the primary time here. I found this board
    and I to find It really helpful & it helped me out a lot.
    I am hoping to provide one thing again and aid others such as you aided me.

Leave a Reply

Your email address will not be published.

*