SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist hessodreamy's Avatar
    Join Date
    Apr 2005
    Location
    uk
    Posts
    525
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    Session variables in secure session

    I've got a shopping cart application which stores purchased items in the session array. However when I switch to a secure session on https the items have vanished.

    My question is: Are session variables transferred when switching from non-secure to secure session?

  2. #2
    SitePoint Addict
    Join Date
    Oct 2004
    Location
    Southwest US
    Posts
    203
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not exactly sure, (please correct me if I'm wrong) but I do not believe the session variables will be available if you change from HTTP to HTTPS. I found some code in the PHP Manual, which I believe will work for you:

    PHP Code:
    function session_redirect ($url "")
       {
           function 
    _safe_set (&$var_true$var_false "")
           {
               if (!isset (
    $var_true))
               { 
    $var_true $var_false; }
           }

           
    $parse_url parse_url ($url);
           
    _safe_set ($parse_url["scheme"], "http");
           
    _safe_set ($parse_url["scheme"], $_SERVER["HTTPS"] ? "https" "http");
           
    _safe_set ($parse_url["path"], "");
           
    _safe_set ($parse_url["query"], "");
           
    _safe_set ($parse_url["fragment"], "");
          
           if (
    substr ($parse_url["path"], 01) != "/")
           {
               
    $parse_url["path"] = dirname ($_SERVER['PHP_SELF']) .
                               
    "/" $parse_url["path"];
           }
          
           if (
    $parse_url["query"] != "")
           { 
    $parse_url["query"] = $parse_url["query"] . "&"; }
           
    $parse_url["query"] = "?" $parse_url["query"] .
                             
    session_name () . "=" .
                           
    strip_tags (session_id ());
          
           if (
    $parse_url["fragment"] != "")
           { 
    $parse_url["fragment"] = "#" $parse_url["fragment"]; }
          
           
    $url $parse_url["scheme"] . "://" $parse_url["host"] .
                 
    $parse_url["path"] . $parse_url["query"] .
                 
    $parse_url["fragment"];
          
           
    session_write_close ();
           
    header ("Location: " $url);
           exit;     
       } 
    The code can be found on this page.
    I have not tested this code becuase I don't have a server setup with HTTPS at the moment.

    Hope this helps
    Itshim


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •