2014-02-21 3 views
0

이 테스트 도메인 Domain Link리디렉션 라이브 서버에서 작동하지 않는

문제의 메신저 카트에서 항목을 제거하고 필요에 사이트에 대한 링크입니다 [해결]. 모든 것은 내 로컬 호스트에서 작동하지만 라이브 서버에 업로드하자 마자 카트에서 항목을 제거하면 작업이 중단되었습니다. 누군가가 잘못되고있는 곳을 말해 줄 수 있습니까? 고마워요.

<?php 
    include_once("../php/cart_config.php"); 
    session_start(); 


    //add item in shopping cart 
    if(isset($_POST["type"]) && $_POST["type"]=='add') 
    { 
     $product_code = filter_var($_POST["product_code"], FILTER_SANITIZE_STRING); //product code 
     $return_url  = base64_decode($_POST["return_url"]); //return url 

     //MySqli query - get details of item from db using product code 
     $results = $mysqli->query("SELECT product_name,price FROM products WHERE product_code='$product_code' LIMIT 1"); 
     $obj = $results->fetch_object(); 

     if ($results) { //we have the product info 

      //prepare array for the session variable 
      $new_product = array(array('name'=>$obj->product_name, 'code'=>$product_code, 'qty'=>1, 'price'=>$obj->price)); 

      if(isset($_SESSION["products"])) //if we have the session 
      { 
       $found = false; //set found item to false 

       foreach ($_SESSION["products"] as $cart_itm) //loop through session array 
       { 
        if($cart_itm["code"] == $product_code){ //the item exist in array 
         $qty = $cart_itm["qty"]+1; //increase the quantity 
         $product[] = array('name'=>$cart_itm["name"], 'code'=>$cart_itm["code"], 'qty'=>$qty, 'price'=>$cart_itm["price"]); 
         $found = true; 
        }else{ 
         //item doesn't exist in the list, just retrive old info and prepare array for session var 
         $product[] = array('name'=>$cart_itm["name"], 'code'=>$cart_itm["code"], 'qty'=>$cart_itm["qty"], 'price'=>$cart_itm["price"]); 
        } 
       } 

       if($found == false) //we didn't find item in array 
       { 
        //add new user item in array 
        $_SESSION["products"] = array_merge($product, $new_product); 
       }else{ 
        //found user item in array list, and increased the quantity 
        $_SESSION["products"] = $product; 
       } 

      }else{ 
       //create a new session var if does not exist 
       $_SESSION["products"] = $new_product; 
      } 

     } 
     //redirect back to original page 
     header('Location:'.$return_url); 
    } 

    //remove item from shopping cart 
    if(isset($_GET["removep"]) && isset($_GET["return_url"]) && isset($_SESSION["products"])) 
    { 
     $product_code = $_GET["removep"]; //get the product code to remove 
     $return_url = base64_decode($_GET["return_url"]); //get return url 

     foreach ($_SESSION["products"] as $cart_itm) //loop through session array var 
     { 
      if($cart_itm["code"]==$product_code){ //item exist in the list 

       //continue only if quantity is more than 1 
       //removing item that has 0 qty 
       if($cart_itm["qty"]>1) 
       { 
       $qty = $cart_itm["qty"]-1; //just decrese the quantity 
       //prepare array for the products session 
       $product[] = array('name'=>$cart_itm["name"], 'code'=>$cart_itm["code"], 'qty'=>$qty, 'price'=>$cart_itm["price"]); 
       } 

      }else{ 
       $product[] = array('name'=>$cart_itm["name"], 'code'=>$cart_itm["code"], 'qty'=>$cart_itm["qty"], 'price'=>$cart_itm["price"]); 
      } 

      //set session with new array values 
      $_SESSION["products"] = $product; 
     } 
     //redirect back to original page 
     header('Location:'.$return_url); 
    } 
    ?> 
+0

php/cart_update.php로 이동하여 소스를 여기에 게시하십시오. :) – Hassan

+0

@hassan : 내가 위에 붙여 넣은 코드는 cart_update.php입니다. – Code

답변

0

HTML이 이미 표시되어 있으면 PHP 헤더를 출력 할 수 없습니다. 대신 Javascript를 사용할 수 있습니다.

?> 
<script type="text/javascript"> 
    window.location = "<?php echo $return_url; ?>"; 
</script> 
<?php 

이 작업은 동일하지만 항상 작동합니다.

+0

덕분에 많은 사람이 당신에게 왕이됩니다. – Code

+0

하지만 이제는 플래시로드를 중단하라는 제안을 아약스에 제안 하시겠습니까? 또는 angularJS? – Code

+0

페이지로드시 플래시를 원하지 않는다면 계획처럼 들리는 AJAX –

관련 문제