Form validation server side

Home » Tutorials » PHP » Form validation server side
Today we’ll consider data validation on server side with build-in php functions. Any html form is potential danger for your project because of information from this form. User not necessary wants to hurt you. He can enter some spaces. Spaces are not a problem, but you are recommended to store clean data.
In this tutorial we will consider several situations%

  1. xss injection detection – we will use strip_tags function
  2. remove spaces – we will use trim function
  3. if you wish to use html tags in input , for this purpose php has hot htmlspecialchars function. This function modify tags into html entities. You can find codes of these entities in Internet.
    For example, this link.

Code lesson

<?php


$login = strip_tags(trim($_POST['login']));
$login = htmlspecialchars(trim($_POST['login']));
$password = $_POST['password'];

if(empty($login) || empty($password)) {
	echo "Error";
} else {
	echo "Вы используете логин $login и пароль $password";
}

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

Pin It on Pinterest

Share This