Jump to content

[SOLVED] loosing session


jakebur01

Recommended Posts

i am trying to implement ssl into my site. My ssl is setup under a different directory on the server (my host set up)      So, i moved my three checkout pages and all of their include files to the new directory. I also changed all the links on the include files to the full path of my regular site for images ect.

 

When i changed the link on the view cart page to the https:// address ..... it loses its session? When i leave the normal directory that the site is under and go to the https:// directory I have it will not pull up the $_SESSION['cart'] from the original directory.

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/64864-solved-loosing-session/
Share on other sites

It is pretty simple hand over from http to https and maintain the session. Here's an example:

 

<?php

session_start();

if(@!$_SERVER['HTTPS']){ // Non - SSL session here

$_SESSION['test'] = 'This was set in the non-SSL part of the session!';

header('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?PHPSESSID='.session_id());

exit;

}

echo $_SESSION['test']; // Now we are in a secure session

?>

i couldn't get it to work.

 

Here is my cart page under http://mysite.com/show_cart.php

<?php
  include ('book_sc_fns.php');
  // The shopping cart needs sessions, so start one
  session_start();

  @ $new = $_GET['new'];

  if($new)
  {
    //new item selected
    if(!isset($_SESSION['cart']))
    {
      $_SESSION['cart'] = array();
      $_SESSION['items'] = 0;
      $_SESSION['total_price'] ='0.00';
    }

    if(isset($_SESSION['cart'][$new]))
      $_SESSION['cart'][$new]++;
    else 
      $_SESSION['cart'][$new] = 1;

    $_SESSION['total_price'] = calculate_price($_SESSION['cart']);
    $_SESSION['items'] = calculate_items($_SESSION['cart']);
  }

  if(isset($_POST['save']))
  {   
    foreach ($_SESSION['cart'] as $isbn => $qty)
    {
      if($_POST[$isbn]=='0')
        unset($_SESSION['cart'][$isbn]);
      else 
        $_SESSION['cart'][$isbn] = $_POST[$isbn];
    }
    $_SESSION['total_price'] = calculate_price($_SESSION['cart']);
    $_SESSION['items'] = calculate_items($_SESSION['cart']);
  }

  do_html_header('Your shopping cart');
  echo "<center><img src=\"images/checkout1.gif\" alt=checkout /></center>";

  if($_SESSION['cart']&&array_count_values($_SESSION['cart']))
    display_cart($_SESSION['cart']);
  else
  {
    echo '<p>There are no items in your cart</p>';
    echo '<hr />';
  }
  $target = 'index.php';

  // if we have just added an item to the cart, continue shopping in that category
  if($new)
  {
    $details =  get_book_details($new);
    if($details['catid'])    
      $target = 'show_cat.php?catid='.$details['catid']; 
  }
  display_button($target, 'continue-shopping', 'Continue Shopping');  

  // use this if SSL is set up
  // $path = $_SERVER['PHP_SELF'];
  // $server = $_SERVER['SERVER_NAME'];
  // $path = str_replace('show_cart.php', '', $path);
  // display_button('https://'.$server.$path.'checkout.php', 
  //                  'go-to-checkout', 'Go To Checkout');  

  // if no SSL use below code
  display_button('https://www.myhostsite.com/folder/myfolder/checkout.php', 'go-to-checkout', 'Go To Checkout');  
  echo "<img src=\"images/checkout_credit_cards.gif\" alt=checkout />";

  
  do_html_footer();
?>

 

and here is the https://www.myhostsite.com/folder/myfolder/checkout.php

<?php
  //include our function set
  include ('book_sc_fns.php');

  // The shopping cart needs sessions, so start one
session_start();
do_html_header('Checkout');
  echo "<center><img src=\"http://mysite.com/images/checkout2.gif\" alt=checkout /></center>";
  ?>
<style type="text/css">
<!--
.style12 {font-family: Georgia, "Times New Roman", Times, serif; font-weight: bold; }
-->
</style>
<!--<table border="1" align="center" bgcolor="#FFFFFF">
  <tr>
    <td><p align="center" class="style12">Shipping is available only in the 48 contiguous United States. </p></td>
  </tr>
</table>!-->
<div align="center"></div>
<div align="center"><?php
  if($_SESSION['cart']&&array_count_values($_SESSION['cart']))
  {
    display_cart($_SESSION['cart'], false, 0);
    display_checkout_form();
  }
  else
    echo '<p>There are no items in your cart</p>';

  display_button('http://mysite.com/show_cart.php', 'continue-shopping', 'Continue Shopping');  

  do_html_footer();
  
?>
</div>
<?php
echo "<img src=\"http://mysite.com/images/checkout_credit_cards.gif\" alt=checkout />";
?>

// use this if SSL is set up
$path = $_SERVER['PHP_SELF'];
  $server = $_SERVER['SERVER_NAME'];
   $path = str_replace('show_cart.php', '', $path);
   display_button('https://'.$server.$path.'checkout.php', 
                   'go-to-checkout', 'Go To Checkout');  

 

How would I implement this if the address I want to go to is : https://mysite.com/myfolder/myname/checkout.php

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.