To secure scripts handling cart functionality, developers should follow modern web standards as outlined by security resources like the OWASP Top Ten:
// Check if item exists in cart $result = $db->query("SELECT * FROM cart WHERE user_id=$user_id AND product_id=$product_id"); if($result->num_rows == 0) { $db->query("INSERT INTO cart (user_id, product_id, quantity) VALUES ($user_id, $product_id, $quantity)"); } else { $db->query("UPDATE cart SET quantity = quantity + $quantity WHERE user_id=$user_id AND product_id=$product_id"); } ?>
Even worse: some implementations allow num to be a like 101_2 to denote product variant ID, leading to IDOR (Insecure Direct Object Reference) attacks where an attacker can add another user's private or unpublished product to their cart.
: Ensuring the requested quantity is available.
$_SESSION['cart'][$_GET['num']] += $_GET['qty'];
But he didn't type a single line.
Set up alerts for:
Register with Facebook to get 5.000 coins free.
REGISTER
Almost there.
To end the process, you have to activate your account by clicking on the link we sent to the email address you provided. add-cart.php num
Close window