Welcome Guest, Not a member yet? Register   Sign In
Best practice in handling invalid parameter
#1

[eluser]Unknown[/eluser]
Hi people,

Let's say I have a method at Controller named

Code:
book($chapter,$page);

where $chapter and $page must be integer. To access the method, the URI will look like

Code:
book/chapter/page

For example,

Code:
book/1/1

If user try to access the URI without passing all parameter, or wrong parameter, like

Code:
book/1/
or
Code:
book/abcxyz/1

I can do some if else statements to handle, like

Code:
if(!empty($page)){
//process
}else{
//redirect
}

My question is, is there any best practice to handle those invalid parameters passed by user? My ultimate goal is to redirect to the main page whenever there is an invalid parameter? How can I achieve this?

Thank you for reading!


I'm sorry for post in the wrong place, please help me to move this to Code! section, thank you so much!




Theme © iAndrew 2016 - Forum software by © MyBB