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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -