I'm working on a very small webshop with a very limited number of projects using codeigniter.
At the start of the script, the products model gets the entire list of products and stores the result as an array as a property of this model.
The product ID's are simply the auto incremented primary keys from the database. So when somebody adds a product to the cart the ID gets sent with POST. I then check three things:
- Could $id be an integer?
- Does this integer exceed the total number of products?
- Does this integer match a product ID?
Basically -although slightly simplified- I do this:
// Count total number of items
$total = count($this->productArray)
if (!(int)$id || $id > $total)
return false;
foreach($this->productArray as $product) {
if ($product['id'] == $id)
return true;
}
return false;