Would this be sufficient validation of a product ID in php? -
i'm working on small webshop limited number of projects using codeigniter.
at start of script, products model gets entire list of products , stores result array property of model.
the product id's auto incremented primary keys database. when adds product cart id gets sent post. check 3 things:
- could $id integer?
- does integer exceed total number of products?
- does integer match product id?
basically -although simplified- this:
// count total number of items $total = count($this->productarray) if (!(int)$id || $id > $total) return false; foreach($this->productarray $product) { if ($product['id'] == $id) return true; } return false;
does integer exceed total number of products?
this not true. delete products out of sync.
that said better idea cast id integer, , query product directly on db. not check against preloaded array; makes no sense.
Comments
Post a Comment