Sayfa2.php gelen sepeti masaya öğeleri saklamak konusunda bazı fikir gerek?

1 Cevap

Yani, O sayfa1.php gelen url kimlikleri değişken alacak, aşağıdaki kod

http://www.stores.com/cart.php?action=add_item&ids=1&qty=1&register=0&id=4

sonra komut işlevi AddItem, UpdateItem ve RemoveItem gelişecektir: o zaman o Miktar ve id değişken hem de o url aşağıdaki gibi int bulundu witht boyunca olguların her kimlikleri görebilirsiniz öğesi eklemek güncelleme veya kaldırmak ya. Bu fonksiyonların her kese ben yanlış değilim eğer bilgi veritabanı içinde id varlığı için acourding veritabanından SELECT, UPDATE ya da DELETE olacaktır. Sonra o açık yanlış değil isem bunun altında büyük bir sorgu tablosu sepeti id göre tablo DKB ve cdkb sonuçları sorgulamak var. Ama bir şey biraz farklılıklar vardır ve yerine kimlikleri içinde IDC değişken ikinci bir sayfa çağrı sayfa2.php olmasıdır.

http://www.stores.com/cart.php?action=add_item&idc=1&qty=1&register=0&id=4

Ben farklı bir şekilde sayfa1.php gelen sonuçlarını görüntülemek ve başka bir şekilde sayfa2.php sonuçlarını görüntülemek için komut sinyali bu iki url bina yanlış olabilir.

    switch($_GET["action"])
     {
        case "add_item":
        {
         AddItem($_GET["ids"], $_GET["qty"]);
         ShowCart();
         break;
       }
        case "update_item":
        {
         UpdateItem($_GET["ids"], $_GET["qty"]);
         ShowCart();
         break;
        }
        case "remove_item":
        {
         RemoveItem($_GET["ids"], $_GET["id"]);
         ShowCart();
         break;
        }
        default:
        {
         ShowCart();
        }
    }
    function AddItem($itemId, $qty){

    $result = mysql_query("SELECT COUNT(*) FROM cart WHERE cookieId = '" . GetCartId() . "' AND id = $itemId");
      $row = mysql_fetch_row($result);
       $numRows = $row[0];

       if($numRows == 0)
      {
       // This item doesn't exist in the users cart,
       // we will add it with an insert query
        mysql_query("INSERT INTO cart(cookieId, id, qty) values('" . GetCartId() . "',   $itemId, $qty)");
       //printf ("Inserted records: %d\n", mysql_affected_rows());

       }
      else
       {
         // This item already exists in the users cart,
         // we will update it instead
         mysql_query("UPDATE cart SET qty = $qty WHERE cookieId = '" . GetCartId() . "' AND id = $itemId");

        }

    }

    function UpdateItem($itemId, $qty)
       {

        mysql_query("UPDATE cart SET qty = $qty WHERE cookieId = '" . GetCartId() . "' AND id = $itemId");
        //printf ("Updated records: %d\n", mysql_affected_rows());
       }

   function RemoveItem($itemId) 
      {

    mysql_query("DELETE FROM cart WHERE cookieId = '" . GetCartId() . "' AND id = $itemId");
    }

    ?>

    <?php 
   function ShowCart()

    {
    $result = mysql_query("SELECT
                  cart.id         cart_id,
                  cart.id         cart_id,
                  cart.cartId     cartId,
                  cart.cookieId   cookie_Id,
                  cart.qty        qt_y,                     
                  cdkb.id         cdkb_id,
                  cdkb.name       name,
                  cdkb.image      image,
                  cdkb.price      price,
                  dkb.id          dkb_id,
                  dkb.name        name1, 
                  dkb.image       image1,
                  dkb.price       price2,
                  dbl.product_id  product_id,
              dbl.price       price3,
              dbl.variety     variety,
              dbl.description description                  
    FROM
        cart


        LEFT OUTER JOIN cdkb
           ON cart.id = cdkb.id    

        LEFT OUTER JOIN dkb
           ON cart.id = dkb.id

        LEFT OUTER JOIN dbl
           ON dbl.id = dkb.id 


    WHERE
        cart.cookieId ='" . GetCartId() . "' ' ORDER BY cdkb.name AND dkb.name ASC");

    <div id="cart">
<div id="group">
<div id="quantity">Qty</div>
<div id="cartpic">Pic</div>
<div id="product">Product</div>
<div id="cartprice">Price</div>
<div id="remove">Remove</div>
</div>
<?php

$totalCost=0;
while($row = mysql_fetch_array($result))
  {  
   // Increment the total cost of all items
   $totalCost += ($row["qt_y"] * $row["price1"]);

 ?>

   <div id="cart1">
   <select name="<?php echo $row["ckb_id"];?>" onChange="UpdateQty(this)">
  <?php  print($row["ckb_id"]);?>
  <?php

   for($i = 1; $i <= 30; $i++)
     {
      echo "<option ";
       if($row["qt_y"] == $i)
         {
          echo " SELECTED ";
         }
        echo ">" . $i . "</option>";
      }
?>
  </select>
  </div>
  <div id="cart2">
  <img src="images/logopic.gif"<?php /*?><?php echo $row["image1"]; ?><?php */?> alt="we" width="60" height="50" />
  </div>
  <div id="cart3"><p><?php echo $row["dishname1"]; ?></p></div>
  <div id="cart4"><p>
  $<?php echo number_format($row["price3"], 2, ".", ","); ?></p></div>

  <div id="cart5">
  <p><?php
  printf('<a href="cart.php?action=remove_item&id=%d&idc=%d&register=%s">Remove</a>',  $_GET['id'], $row['ckb_id'], $_GET['register']);
?></p></div>

<hr size="1" color="red" >

<script language="JavaScript">

function UpdateQty(item)
  {
   itemId = item.name;
   newQty = item.options[item.selectedIndex].text;

   document.location.href = 'cart.php?action=update_item&id='+itemId+'&qty='+newQty;
  }

</script>

  <?php
   }
   ?>

   <font face="verdana" size="2" color="black" style="clear:right;">
   <b>Total: $<?php echo number_format($totalCost, 2, ".", ","); ?></b></font></td>


   <?php
    }
    ?>

1 Cevap

Sen url gelen miktar ve diğer şeyler alıyorsanız, bu benim görüşüme göre iyi bir uygulama (Eğer url gizli bir şey koyarak olmasa da), url tavlama yapılabilir değil, XSS saldırıları adresler ve giriş alanlarında hem ortak alma yeri vardır. Ben yerine session kullanmanızı öneririm. Tabii ki hiçbir şey mükemmel değildir, ama o daha az savunmasız hale getirir.