php - Best practices to deal with absent/wrongly typed GET variables? -


When you find that your request has been broken or the wrong type of data is passing, what do you do? Say you have a forum-page Php? Forum = 3 which lists all the topics related to stage 3.

What would be a good way to deal with the lack of "forum" variables? Instead of being an integer, you get a string?

  • If the forum-page Php is said without a "forum", so you get an error saying why you have not requested
  • The variable is redirected to just a default page, like some forums-page.php? Forum = 1 There is only one thing for wrong type variables.
  • Redirect to another page.
  • Other options?
  • Do not really love to read your opinion about this.

    I usually return a 400 (bad request) state status (for example "Stage parameter is required"). Not sure if PHP allows this (ASP.NET), but then you can map to a 400 on a custom page that displays the error in the way that your app understands.


    Comments

    Popular posts from this blog

    MySql variables and php -

    url rewriting - How to implement the returnurl like SO in PHP? -

    Which Python client library should I use for CouchdB? -