Jump to content

No intval....

- - - - -

  • Please log in to reply
1 reply to this topic

#1
bbqroast

bbqroast

    Codecall Addict

  • Members
  • PipPipPipPipPipPipPip
  • 554 posts
  • Location:/etc/passwd
You know those things that make you want to grind your nails along a desk? Well here's one of 'em:
Having spent a while working on security you suddenly discover that your intval() checking means that going to the page with an ID of two will put you on the page with an ID of one!

$page = $_GET['p'];

if (intval($pageID) == 0){

$page = 0;

} else if (intval($pageID) == 1) {

$page = 0;

}

$pageID = $page + 1;

As you can see we GET the variable 'p' then check its an int before adding one on to it (as the 'p' variable starts at 0 and MySQL's page IDs start at 1).
Apparently if $pageID is not a number it will return 0 or 1- However sadly intval returns $pageID on success so if $pageID is page two then it sees it as invalid and tells php to show the homepage instead.

So any ideas for a workaround?

Gosh writing makes me thirsty...
Please, write clearly with proper structure. Double spacing makes the text feel un-jointed, Capitalizing Every Word Means People Stop Before Every Word Sub-Consciously Which Is A Pain In The Backside, and use code tags! (The right most styling box).

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
What you are stating is contradictory to what you have written, for example you are applying intval to $pageID and not $page which contains the P array index, what is $pageID? Where is it filled and what is its correlation to $page?

A note, intval is a problematic function in PHP, as PHP will automatically type cast most of what you need. "3" == 3, but with intval, "e" can == 0, or your first page which you have described. You should check this with is_int() and throw an error if it is not an integer value.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users