March 2, 200917 yr Ok, anybody like to suggest why the following: if(isset($_GET['page'])){ $page = $_GET['page']; } else { $page = 1; } echo $page; returns '1' when I go to file.php?page=43 But when I do this: if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } echo $page; using the same query, I receive '43'.
March 3, 200917 yr That seems to defy logic - isset is returning both true and false with the same input?! Are you absolutely sure it has the same input and you've copied/pasted correctly in each example? On a side note, you'd be better using either is_numeric() or intval() so you can simultaneously check if the value is in fact a positive integer. For example, this pretty much does what you want (I think - I haven't tested it): if(($page = intval($_GET['page'])) <= 0) $page = 1; Note intval() returns 0 if the argument cannot be parsed to an integer, and this test rules out all non-positive integers too.
March 3, 200917 yr Author Yeah I'm positive. I was staring at it for ages but then tested it on my localhost and it worked (as it should). I will change the code to use the functions you mentioned as it is a lot more efficient. Do you recommend I contact my hosts about their PHP?
Create an account or sign in to comment