Folks,
I want to check if the page number exists in url or not. If not then by default the page nu8mber should be “1”.
(Imagine a SERP. They usually contain page number in their urls).
Notice my questions in the comments of my two codes. And try answering them.
Is this code ok or faulty ?
“`
if(!empty($_REQUEST[‘page’]) && is_int($_REQUEST[‘page’]))
{
$page_no = strip_tags(stripslashes($_REQUEST[‘page’])); //Is strip_tags() or stripslashes() necessary here ?
}
else
{
//If Page Number not in Url then default the page number to: 1.
$page_no = INT(1); //Which one is correct ?
$page_no = INTVAL(1); //Which one is correct ?
}
How to shorten the code ?
My attempt to shorten it:
Is this code ok or faulty ?
“`
if(!empty($_REQUEST[‘page’]) && is_int($_REQUEST[‘page’]))
{
$page_no = strip_tags(stripslashes($_REQUEST[‘page’])) : $page_no = 1; //Is strip_tags() or stripslashes() necessary here ?
//Is this part valid or not: “: **$page_no = 1;**”
}
else
{
//If Page Number not in Url then default the page number to: 1.
$page_no = INT(1); //Which one is correct ?
$page_no = INTVAL(1); //Which one is correct ?
}
Show us how you would write it.