Results 1 to 5 of 5

Thread: How to do Validating and Sanitizing in PHP?

  1. #1
    Join Date
    Apr 2009
    Posts
    460

    How to do Validating and Sanitizing in PHP?

    Hello Guys,
    I have done some basic things in PHP, so I don't have enough knowledge about the PHP programming language. Recently I have started the topic of the filters. I understood the filters but I am unable to grab the validation and sanitization done by using the filters. Please tell me how to do Validating and Sanitizing in PHP? Reply me as soon as possible.!!

  2. #2
    Join Date
    Jul 2006
    Posts
    286

    Re: How to do Validating and Sanitizing in PHP?

    You should know that data validation is an integral part of working with forms. Using the filters are very important because an invalid submitted data may lead to security problems and also it can break your web-page. So I would like to recommend you to use the filters in your program to keep the web page safe. You can validate data by using the "filter_var" function. Validation is used to ensure that the data is strongly typed, correct syntax, within length boundaries, contains only permitted characters, or that numbers are correctly signed and within range boundaries.
    IF you hate me, please don't mention it. I know who hates me and who doesn't. You really do not have to make fun of people....

  3. #3
    Join Date
    Mar 2008
    Posts
    349

    Re: How to do Validating and Sanitizing in PHP?

    While talking about validating and sanitizing, I am assuming that you are having knowledge about the filters. PHP has several built-in filter_* functions that can assist with validating and sanitizing email addresses, URLs, strings, integers, float values, etc. There are two kinds of filters :
    • Validating filters
    • Sanitizing filters
    I normally tell people to eliminate or translate characters in an effort to make the input "safe".

  4. #4
    Join Date
    Jul 2006
    Posts
    442

    Re: How to do Validating and Sanitizing in PHP?

    While learning about the filters, you should also have knowledge about an options and flags that are used to add additional filtering options to the specified filters. Different filters have different options and flags. The following sample of coding explains the validation of an integer using the filter_var() and the "min_range" and "max_range" options :
    PHP Code:
    <?php
    $var
    =500;

    $int_options = array(
    "options"=>array
      (
      
    "min_range"=>0,
      
    "max_range"=>456
      
    )
    );

    if(!
    filter_var($varFILTER_VALIDATE_INT$int_options))
      {
      echo(
    "Integer is not valid");
      }
    else
      {
      echo(
    "Integer is valid");
      }
    "When they give you ruled paper, write the other way..." J.R.J.

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: How to do Validating and Sanitizing in PHP?

    You can validate your input from the form by using the following coding :
    PHP Code:
    <?php
    if(!filter_has_var(INPUT_GET"email"))
      {
      echo(
    "Input not Proper");
      }
    else
      {
      if (!
    filter_input(INPUT_GET"email"FILTER_VALIDATE_EMAIL))
        {
        echo 
    "E-Mail is not valid";
        }
      else
        {
        echo 
    "E-Mail is valid";
        }
      }
    ?>
    In the example above, the input variable "email" is sent to the PHP page.

Similar Threads

  1. Problem validating TAILS download
    By sanctimonious-saliva in forum Operating Systems
    Replies: 3
    Last Post: 04-09-2013, 10:37 AM
  2. VB: Validating Username and Password In CSV File
    By admoore01 in forum Software Development
    Replies: 1
    Last Post: 26-11-2011, 05:25 PM
  3. Why my wireless is asking validating identity
    By Krishanu in forum Networking & Security
    Replies: 6
    Last Post: 16-10-2010, 02:46 PM
  4. Validating Data in Java
    By Ucchal in forum Software Development
    Replies: 5
    Last Post: 10-08-2010, 10:42 AM
  5. Validating Email in Java
    By KALYAN23 in forum Software Development
    Replies: 3
    Last Post: 04-11-2009, 05:24 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,716,601,809.30171 seconds with 17 queries