Validating url php

Rated 3.94/5 based on 805 customer reviews

If you are sending sensitive data such as passwords, emails with HTTP request you must use POST. But, if the email is compulsory, we have to throw an error if it's empty.

If you are retrieving data from the server, you can use GET method. Here I have chosen POST method and the action script, is requested with any other method, it will show an error. Next, we have to check the user inputs to avoid processing errors. Assume that you have php code to assign POST variable to a local variable as following. The last subtopic of this tutorial will explain you to do that in an object oriented way. We save his username in the database without any validation.

Of course, validating user input is really important for dynamic websites. In this tutorial, you will learn about 4 major tasks.

The awesome language, PHP has numerous in-built functions to validate user inputs.

So, in the next step we will be creating a class to validate inputs in a more convenient way.

validating url php-58

The advantage of using this function is, it converts string numbers ( function.

So, every user who visits this page will be redirected to function to validate variables.

We can set it's second parameter to different values and use it to validate emails, URLs, integers, booleans, etc.

If you are interested in autoloading classes, you can check our tutorial.

As in the above code, I have created the method // validate an integer $number = Input::int($_POST['number']); // validate a string $name = Input::str($_POST['name']); // convert to boolean $bool = Input::bool($_POST['boolean']); // validate an email $email = Input::email($_POST['email']); // validate a URL $url = Input::url($_POST['url']); function was described with it's filters with examples.

Leave a Reply