jakebur01 Posted August 14, 2007 Share Posted August 14, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/64864-solved-loosing-session/ Share on other sites More sharing options...
lemmin Posted August 14, 2007 Share Posted August 14, 2007 I think the default session save path is relative to the server root folder. Try setting it to something absolute like c:\ and see if you can access it. http://us2.php.net/manual/en/function.session-save-path.php Quote Link to comment https://forums.phpfreaks.com/topic/64864-solved-loosing-session/#findComment-323651 Share on other sites More sharing options...
jakebur01 Posted August 14, 2007 Author Share Posted August 14, 2007 I don't understand. What do I need to do now? Quote Link to comment https://forums.phpfreaks.com/topic/64864-solved-loosing-session/#findComment-323655 Share on other sites More sharing options...
m1a2x3x7 Posted August 14, 2007 Share Posted August 14, 2007 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/64864-solved-loosing-session/#findComment-323656 Share on other sites More sharing options...
jakebur01 Posted August 14, 2007 Author Share Posted August 14, 2007 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 />"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/64864-solved-loosing-session/#findComment-323678 Share on other sites More sharing options...
jakebur01 Posted August 14, 2007 Author Share Posted August 14, 2007 // 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 Quote Link to comment https://forums.phpfreaks.com/topic/64864-solved-loosing-session/#findComment-323696 Share on other sites More sharing options...
jakebur01 Posted August 14, 2007 Author Share Posted August 14, 2007 anybody? I know what I want to do, I just don't know how to do it. Quote Link to comment https://forums.phpfreaks.com/topic/64864-solved-loosing-session/#findComment-323707 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.