Jump to content

Recommended Posts

Posted

$sanitizer->int() or php natives (int) or intval() will do.

post-1041-0-33961000-1460718814_thumb.jp

Looking up in tools like API-gen, maintained (with everytime the newest codebase) by Kongondo, is much more faster than asking (such simply code/method related things) in the forums. :)

I highly suggest to use this. It will save you a lot of time, that you otherwise have to wait until someone other answers your questions. :)

---

EDIT: Oh damn, - @arjen beats me, while I made the screenshot!

  • Like 5
Posted

Even better is $sanitizer->intUnsigned() as id's cannot be negative.

Which, in plain vanilla PHP is

$pageID = abs(intval($id));

;)

  • Like 3
Posted

Usually like this.

$id = (int) $input->post->id;
$p = $pages->get("id=$id, template=dings");
if($p->id){
    // valid
} else {
   // not valid
}
  • Like 2
Posted

Soma is right here. It isn't enough to sanitize to an integer, you also need to add some own logic, that reflects what you are expecting. :)

Posted

intUnsigned() is still better, because you won't hit the db for an possibly invalid id, even though negative values might be a rare edgecase.

Posted

Soma is right here. It isn't enough to sanitize to an integer, you also need to add some own logic, that reflects what you are expecting. :)

What I exactly meant is: sanitizing with intUnsigned() and add some own logic (template or equal). :)

Posted

If negative is a issue at all then 

if($id){ ... }

what? :huh:

please try:

foreach(array(-5, -1, 0, 1, 5) as $id) {
    var_dump((bool)$id);
}
  • Like 3
Posted

Ah yes right, negative evals to true.

So then correcting mine: :D

if($id > 0){...} 

But don't see why that would be an issue to have a negative page id it won't find it anyway.

  • Like 2
Posted

It's not an issue in terms of security, but rather a (probably small) performance consideration. It just prevents an unnecessary mysql query in case a negative int is supplied. 

  • Like 2

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...