sKunKbad Posted May 13, 2007 Share Posted May 13, 2007 If I view my script Opera and Firefox, I am having some various problems that don't exist in IE6 or IE7, and I think they may be due to the way that Firefox and Opera handle cookies, but I'm not sure. If anyone can look at my script at tell me if there are some problems I'd appreciate it. BTW, php.ini is set for session.use_trans_sid=1. Thank you. This live testing page is at http://www.sewingcenter.tv/abc.php5?Action=Search <?php session_name(bookstoreID); session_set_cookie_params(604800); session_start(); ?> <?php define('KEYID','1KSDRC8DMVTJ0HEKBSG2'); define('AssocTag','temevallsewic-20'); if (isset($_SESSION['SessionCartId'])){ $CartId = $_SESSION['SessionCartId']; }else{ $CartId = ''; } if (isset($_SESSION['HMAC'])){ $HMAC = $_SESSION['HMAC']; }else{ $HMAC = ''; } if($_GET['Action'] == 'Search'){ print(" <div class='right-column'> <div class='greenbox-top'></div> <div class='greenbox-bg'> <form action='{$_SERVER['PHP_SELF']}' method='get'> <h2>Book Search</h2> <p style='margin-top:16px;' class='heavy'>Search For:</p> <div><input type='hidden' name='SearchIndex' value='Books' /></div> <p><input type='text' name='SearchString' size='24'/></p> <p style='margin-top:16px;' class='heavy'>Search By: <select name='SearchBy'> <option value='Title'>Title </option> <option value='Author'>Author</option> <option value='Keywords'>Keywords</option> </select></p> <div><input type='hidden' name='Action' value='Search' /></div> <div><input type='hidden' name='Page' value='1' /></div> <div><input type='hidden' name='NextPage' value='2' /></div> <p style='margin-top:16px'><input type='submit' value='Search!'/></p> </form> "); if($_SESSION['SessionCartId'] != ''){ $CartGet = "{$_SERVER['PHP_SELF']}?Action=CartGet"; print("<p class='heavy' style='text-align:center; margin-top:15px;'><img src='img/cart.gif' alt='shopping cart button'/> <a href='$CartGet'>View Cart</a></p>"); } print(" </div> <div class='greenbox-bottom'></div> "); print(" </div> <!-- Some stuff taken out here just to help reduce the amount of code you need to look at --> "); } ?> <?php if($_GET['Action'] == 'Search'){ if ($_GET['SearchString'] == ''){ print(" <h2>Search Now!</h2> "); } else{ $SearchString = urlencode($_GET['SearchString']); ItemSearch($_GET['SearchIndex'], $SearchString, $_GET['SearchBy'], $_GET['Page'], $_GET['NextPage']); } } if($_GET['Action'] == 'SeeDetails'){ ItemLookup($_GET['ASIN'], $_GET['SearchIndex']); } if($_GET['Action'] == 'CartAdd'){ if(!isset($_SESSION['OfferListingId']['0'])){ getCartContents(); }else{ if($CartId != ''){ CartAdd(); }else{ CartCreate(); } } } if($_GET['Action'] == 'Remove'){ removeFromCart($_GET['CartItemId']); } if($_GET['Action'] == 'CartGet'){ getCartContents(); } if($_GET['Action'] == 'AddChoice'){ if(!isset($_SESSION['OfferListingId'])){ getCartContents(); }else{ $Choice = $_GET['Choice']; $_SESSION['OfferListingId']['0'] = $_SESSION['OfferListingId']["$Choice"]; if($CartId != ''){ CartAdd(); }else{ CartCreate(); } } } ?> <?php function ItemSearch($SearchIndex, $SearchString, $SearchBy, $Page, $NextPage){ $request="http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService"; $request.="&AWSAccessKeyId=".KEYID."&AssociateTag=".AssocTag."&ItemSearch.Shared.Version=2006-09-11"; $request.="&Operation=ItemSearch&ItemSearch.Shared.ResponseGroup=Medium,Offers"; $request.="&ItemSearch.Shared.SearchIndex=$SearchIndex"; $request.="&ItemSearch.Shared.$SearchBy=$SearchString"; $request.="&ItemSearch.1.ItemPage=$Page"; $request.="&ItemSearch.2.ItemPage=$NextPage"; $session = curl_init($request); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($session); curl_close($session); $parsed_xml = simplexml_load_string($response); printSearchResults($parsed_xml, $SearchIndex); } //------------------------------------------------------------------------------------------------------ function printSearchResults($parsed_xml, $SearchIndex){ unset($_SESSION['OfferListingId']); $numOfItems = $parsed_xml->Items->TotalResults; $totalPages = $parsed_xml->Items->TotalPages; print("<h2>Your Search Results</h2>"); print("<div style='width:438px;'>\n"); if($numOfItems>0){ $Choice = 0; foreach($parsed_xml->Items as $Items){ foreach($Items->Item as $current){ if(isset($current->Offers->Offer->OfferListing->OfferListingId)){ //only show items for which there is an offer print("\t\t\t<div style='width:438px; float:left; padding-bottom:15px; padding-top:15px; border-bottom: solid red 2px;'><img style='margin-left:40px; clear:both;' src='".$current->SmallImage->URL."' alt='small cover image' />\n"); print("\t\t\t<p style='font-weight:bold;'>".utf8_decode(str_replace("&", "&", $current->ItemAttributes->Title))."</p>\n"); print("\t\t\t<p>Author: ".utf8_decode($current->ItemAttributes->Author)."</p>\n"); print("\t\t\t<p>Price: ".$current->Offers->Offer->OfferListing->Price->FormattedPrice."</p>\n"); $asin = $current->ASIN; $details = "{$_SERVER['PHP_SELF']}?Action=SeeDetails&ASIN=$asin&SearchIndex=$SearchIndex"; print("\t\t\t<p style='margin-left:40px;'><a href='$details'>See Details</a></p>\n"); $_SESSION['OfferListingId'][] = (string)$current->Offers->Offer->OfferListing->OfferListingId; $CartAdd = "{$_SERVER['PHP_SELF']}?Action=AddChoice&Choice=$Choice"; print("\t\t\t<p style='margin-left:40px;'><a href='$CartAdd'>Add to Cart</a></p>\n"); print("\t\t</div>\n\n"); $Choice++; } } } }else{ print("<center>No matches found.</center>"); } print("</div>"); print("<div style='float:left; width:100%; margin-top:25px; margin-bottom:20px;'>"); if($_GET['Page'] > 1 && $totalPages > 2){ $SearchString = urlencode($_GET['SearchString']); $SearchBy = $_GET['SearchBy']; $Page = $_GET['Page']-2; $NextPage = $Page +1; $prevPage = "{$_SERVER['PHP_SELF']}?Action=Search&SearchIndex=$SearchIndex&SearchBy=$SearchBy&SearchString=$SearchString&Page=$Page&NextPage=$NextPage"; print("<div style='float:left; width:50%; text-align:right'><p><a href='$prevPage'>Previous Page</a></p></div>"); } if($_GET['NextPage'] < $totalPages){ $SearchString = urlencode($_GET['SearchString']); $SearchBy = $_GET['SearchBy']; $Page = $_GET['Page']+2; $NextPage = $Page +1; $nextPageSet = "{$_SERVER['PHP_SELF']}?Action=Search&SearchIndex=$SearchIndex&SearchBy=$SearchBy&SearchString=$SearchString&Page=$Page&NextPage=$NextPage"; print("<div style='float:left; width:45%; padding-left:5%;'><p><a href='$nextPageSet'>Next Page</a></p></div>"); } print("</div>"); } //------------------------------------------------------------------------------------------------------- function ItemLookup($asin, $SearchIndex){ $request = "http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=".KEYID."&AssociateTag=".AssocTag."&Version=2006-09-11&Operation=ItemLookup&ItemId=$asin&ResponseGroup=Medium,Offers"; $session = curl_init($request); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($session); curl_close($session); $parsed_xml = simplexml_load_string($response); printDetails($parsed_xml, $SearchIndex); } //------------------------------------------------------------------------------------------------------- function printDetails($parsed_xml, $SearchIndex){ print("<div id='details'>\n"); print("\t\t\t<div style='position:relative; float:right; width:25%; margin-top:20px;'>\n\t\t\t\t<img src='".$parsed_xml->Items->Item->MediumImage->URL."' alt='medium cover image' />\n\t\t\t</div>\n"); print("\t\t\t<div style='position:relative; float:left; width:70%; margin-top:20px;'>\n\t\t\t\t<p style='font-weight:bold;'>".utf8_decode(str_replace("&", "&", $parsed_xml->Items->Item->ItemAttributes->Title))."</p>\n"); print("\t\t\t\t<p>Author: ".utf8_decode($parsed_xml->Items->Item->ItemAttributes->Author)."</p>\n"); print("\t\t\t\t<p>".$parsed_xml->Items->Item->ItemAttributes->Binding."</p>\n"); print("\t\t\t\t<p>".$parsed_xml->Items->Item->ItemAttributes->NumberOfPages." pages</p>\n"); if ($parsed_xml->Items->Item->EditorialReviews->EditorialReview->Content != ''){ print("\t\t\t\t<p style='border:dashed green 3px; padding:10px; margin:10px 0px 10px 0px;'>".utf8_decode(str_replace("<br>", "<br />", strip_tags($parsed_xml->Items->Item->EditorialReviews->EditorialReview->Content, '<br><i><b><strong><em>')))."</p>\n"); } print("\t\t\t\t<p style='font-weight:bold;'>".$parsed_xml->Items->Item->Offers->Offer->OfferListing->Price->FormattedPrice."</p>\n"); $_SESSION['OfferListingId']['0'] = (string)$parsed_xml->Items->Item->Offers->Offer->OfferListing->OfferListingId; $CartAdd = "{$_SERVER['PHP_SELF']}?Action=CartAdd"; print("\t\t\t\t<p style='font-weight:bold;'><a href='$CartAdd'>Add to Cart</a></p>\n"); $search = "{$_SERVER['PHP_SELF']}?Action=Search"; print("\t\t\t\t<p style='font-weight:bold;'><a href='$search'>Continue Searching</a></p></div>\n"); print("\t\t\t</div>\n"); print("\t\t\t<div class='bloodline'>\n\t\t</div>\n"); } //------------------------------------------------------------------------------------------------------- function cartCreate(){ if (isset($_SESSION['HMAC'])){ //this could have checked for the SessionCartId and the result would have been the same getCartContents(); }else{ $request="http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=".KEYID."&AssociateTag=".AssocTag."&Version=2006-09-11&Operation=CartCreate&Item.1.OfferListingId=".$_SESSION['OfferListingId']['0']."&Item.1.Quantity=1"; $session = curl_init($request); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($session); curl_close($session); $parsed_xml = simplexml_load_string($response); $_SESSION['SessionCartId'] = (string)$parsed_xml->Cart->CartId; $preHMAC = (string)$parsed_xml->Cart->URLEncodedHMAC; $_SESSION['HMAC'] = str_replace("+", "%2b", $preHMAC); showCartContents($parsed_xml); } } //------------------------------------------------------------------------------------------------------- function cartAdd(){ $CartId = $_SESSION['SessionCartId']; $HMAC = $_SESSION['HMAC']; $request="http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=".KEYID."&AssociateTag=".AssocTag."&Version=2006-09-11&Operation=CartAdd&CartId=$CartId&HMAC=$HMAC&Item.1.OfferListingId=".$_SESSION['OfferListingId']['0']."&Item.1.Quantity=1"; $session = curl_init($request); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($session); curl_close($session); $parsed_xml = simplexml_load_string($response); showCartContents($parsed_xml); } //------------------------------------------------------------------------------------------------------- function showCartContents($parsed_xml){ print("<h2>Shopping Cart</h2>\n"); unset($_SESSION['OfferListingId']); $color1 = "#FFFF80"; $color2 = "#FFEF66"; $row_count = 0; $isCartEmpty = 0; foreach($parsed_xml->Cart->CartItems->CartItem as $current){ $row_color = ($row_count % 2) ? $color1 : $color2; $CartItemId = $current->CartItemId; $remove="{$_SERVER['PHP_SELF']}?Action=Remove&CartItemId=$CartItemId"; print("<div style='position:relative; float:left; padding:10px; background-color:$row_color; width:667px; height:100%; font-weight:bold;'>\n\t<div style='float:left; width:449px;'>\n\t\t<p>".utf8_decode(str_replace("&", "&", $current->Title)).": </p>\n\t</div>\n\t<div style='float:left; width:66px;'>\n\t\t<p>".$current->Price->FormattedPrice."</p>\n\t</div>\n\t<div style='float:left; width:132px;'>\n\t\t<p style='padding:0;'><a href='$remove'>(Remove from Cart)</a></p>\n\t</div>\n</div>\n"); $row_count++; $isCartEmpty++; } if($isCartEmpty == 0){ print("<p style='color:red;'>Your Shopping Cart Is Now Empty.</p>\n"); } if($isCartEmpty != 0){ print("<div style='float:left; clear:left; width:100%; margin-top:10px; font-weight:bold;'>\n\t<p>Subtotal: ".$parsed_xml->Cart->CartItems->SubTotal->FormattedPrice."</p>\n</div>\n"); } $continue = "{$_SERVER['PHP_SELF']}?Action=Search"; print("<div style='float:left; clear:left; width:100%; font-weight:bold;'>\n\t<p><a href='$continue'>Continue Shopping</a></p>\n</div>\n"); if($isCartEmpty != 0){ $checkout=$parsed_xml->Cart->PurchaseURL; print("<div style='float:left; clear:left; width:100%; font-weight:bold;'>\n\t<p><a href='$checkout'>Checkout Now</a></p>\n</div>\n"); } } //------------------------------------------------------------------------------------------------------ function removeFromCart($CartItemId){ $CartItemId = $_GET['CartItemId']; $request = "http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=".KEYID."&AssociateTag=".AssocTag."&Version=2006-09-11&Operation=CartModify&CartId=".$_SESSION['SessionCartId']."&HMAC=".$_SESSION['HMAC']."&Item.1.CartItemId=$CartItemId&Item.1.Quantity=0"; $session = curl_init($request); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($session); curl_close($session); $parsed_xml = simplexml_load_string($response); showCartContents($parsed_xml); } //----------------------------------------------------------------------------------------------------- function getCartContents(){ $request = "http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=".KEYID."&AssociateTag=".AssocTag."&Version=2006-09-11&Operation=CartGet&CartId=".$_SESSION['SessionCartId']."&HMAC=".$_SESSION['HMAC']; $session = curl_init($request); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($session); curl_close($session); $parsed_xml = simplexml_load_string($response); showCartContents($parsed_xml); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/51235-session-problems-in-firefox-and-opera/ Share on other sites More sharing options...
toplay Posted May 13, 2007 Share Posted May 13, 2007 I didn't look through all that code, however, I see a problem with this command: session_name(bookstoreID); If bookstoreID is defined as a constant with an alphanumeric value, then it's fine. Or maybe you meant to have it as: session_name('bookstoreID'); // The session name is missing quotes around it If bookstoreID is a constant and defined as just a numeric value, then that won't work. See warning on this page: http://us2.php.net/manual/en/function.session-name.php Quote Link to comment https://forums.phpfreaks.com/topic/51235-session-problems-in-firefox-and-opera/#findComment-252383 Share on other sites More sharing options...
sKunKbad Posted May 13, 2007 Author Share Posted May 13, 2007 I did make that change to session_name to include quotes, but it didn't fix my problem. Quote Link to comment https://forums.phpfreaks.com/topic/51235-session-problems-in-firefox-and-opera/#findComment-252407 Share on other sites More sharing options...
toplay Posted May 13, 2007 Share Posted May 13, 2007 After changing it to include quotes, did you remember to delete all the cookies before testing again? You have to change it to include quotes in all the PHP pages where it has a session_start(). If you're using sessions to hold shopping cart type of stuff, why have the session cookie stick around for so long (7 days)? Anyway, you need to start putting echo to help yourself debug this. Display all the session data at the top of your script. i.e.: echo '<pre>', print_r($_SESSION, TRUE), '</pre>'; If the session data displays as you expect, then the session is being saved and everything is fine on the PHP side and it's probably a bug in your logic/code. Quote Link to comment https://forums.phpfreaks.com/topic/51235-session-problems-in-firefox-and-opera/#findComment-252422 Share on other sites More sharing options...
sKunKbad Posted May 13, 2007 Author Share Posted May 13, 2007 I did delete the cookie before retesting. I have the shopping cart cookie info set to expire in 7 days because that is how long the cart exists on the Amazon server unless modified. I have been using print_r, and the actual cookie array is there... so I guess it may not be the cookie, but because the script works fine in IE, but not firefox or opera, I was assuming that the problem had to be something related to client side. Quote Link to comment https://forums.phpfreaks.com/topic/51235-session-problems-in-firefox-and-opera/#findComment-252429 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.