PHP Front To Back [Part 14] – Filters & Validation

In this video we will look at PHP filters and how to validate data types, emails, urls, etc. We will also be able to sanitize data. Functions will include

filter_has_var()
filter_input()
filter_var()
filter_input_array()
filter_var_array()

CODE: Code for this video
http://www.traversymedia.com/downloads/phpsandbox/phpsandbox12.zip

EDUONIX COURSES: Please use affiliate links from website below
http://www.traversymedia.com/eduonix-…

SUPPORT: We spend massive amounts of time creating these free videos, please donate to show your support:
http://www.paypal.me/traversymedia
http://www.patreon.com/traversymedia

FOLLOW TRAVERSY MEDIA:
http://www.facebook.com/traversymedia

http://www.linkedin.com/bradtraversy

source by Traversy Media

php language

Mourad ELGORMA

Fondateur de summarynetworks, passionné des nouvelles technologies et des métiers de Réseautique , Master en réseaux et système de télécommunications. ,j’ai affaire à Pascal, Delphi, Java, MATLAB, php …Connaissance du protocole TCP / IP, des applications Ethernet, des WLAN …Planification, installation et dépannage de problèmes de réseau informatique……Installez, configurez et dépannez les périphériques Cisco IOS. Surveillez les performances du réseau et isolez les défaillances du réseau. VLANs, protocoles de routage (RIPv2, EIGRP, OSPF.)…..Manipuler des systèmes embarqués (matériel et logiciel ex: Beaglebone Black)…Linux (Ubuntu, kali, serveur Mandriva Fedora, …). Microsoft (Windows, Windows Server 2003). ……Paquet tracer, GNS3, VMware Workstation, Virtual Box, Filezilla (client / serveur), EasyPhp, serveur Wamp,Le système de gestion WORDPRESS………Installation des caméras de surveillance ( technologie hikvision DVR………..). ,

50 réflexions sur “PHP Front To Back [Part 14] – Filters & Validation

  • juin 11, 2021 à 4:57
    Permalien

    Also when I do a search for filter_sanitize_email on php.net I get a message that says filter_sanitize_email does not exist. Is this filter maybe deprecated?

    Répondre
  • juin 11, 2021 à 4:57
    Permalien

    Do you not need to use htmlspecialcharcters for the action if using php self? I’m a novice but I remover reading that somewhere to avoid malicious scripts

    Répondre
  • juin 11, 2021 à 4:57
    Permalien

    When i had both FILTER_SANITIZE_NUMBER_INT and FILTER_SANITIZE_SPECIAL_CHARS turned on, alert would fire, but there was also a copy of alert which was stopped..

    Répondre
  • juin 11, 2021 à 4:57
    Permalien

    Would it work if we used ternary operator instead of the nested if/else? something like
    if(filter_has_var(INPUT_POST, 'data')) {
    (filter_input(INPUT_POST, 'data', FILTER_VALIDATE_EMAIL)) ? echo 'Email is valid'; : echo 'Email is not valid';
    }

    Répondre
  • juin 11, 2021 à 4:57
    Permalien

    The sanitizer. It worked the first time, but after that it only cleans up slashes and stuff. I have php 7.1.20

    Répondre
  • juin 11, 2021 à 4:57
    Permalien

    My filter_var code is not working:

    if(filter_has_var(INPUT_POST, 'data')){
    $email = $_POST['data'];

    // Remove illegal chars
    $email = filter_var($email, FILTER_SANITIZE_EMAIL);
    echo $email.'<br>';

    if(filter_var($email, FILTER_VALIDATE_EMAIL)){
    echo 'Email is valid';
    } else {
    echo 'Email is NOT valid';
    }
    }

    I still echo invalid email
    test^&%&%@test&^&*^.com

    Répondre
  • juin 11, 2021 à 4:57
    Permalien

    Thank you so much for this great course!
    I tried to use FILTER_SANTIZE_NUMBER_INT BUT it returns NULL why?
    $var = '33k2jjj325k254khff25';
    $newVar = filter_var($var, FILTER_SANTIZE_NUMBER_INT);
    var_dump($newVar);

    Répondre
  • juin 11, 2021 à 4:57
    Permalien

    @7:45 Why switch from filter_input() to filter_var()? I understand filter_var() will sanitize the data so that it will pass, but do we really want it passing and taking up space in our database if a person enters something like test[]@\///test.net? Even though it passes, it will most likely not be a real email. Wouldn't it be better to have the validation fail and have the user re-enter their email?

    PS. I love your videos. Thanks for sharing!

    Répondre
  • juin 11, 2021 à 4:57
    Permalien

    If you had front end JavaScript field validations do you need to then have php validations? In that case do you just need php to sanitize the inputted data and submit the form?

    Répondre
  • juin 11, 2021 à 4:57
    Permalien

    can please some one tell me how does this work

    $filters = array(

    "data"=>FILTER_VALIDATE_EMAIL,

    "data2"=>array(

    "filter"=>FILTER_VALIDATE_INT,

    "options"=>array(

    "min_range"=>1,

    "max_range"=>100

    )

    )

    );

    Répondre
  • juin 11, 2021 à 4:57
    Permalien

    MAAN. Honestly speaking you should teach teachers how to teach.. There are a lot of courses paid and free, but how you explain in short period of time critical things to understand it's a gods gift. You deserve like Nobel Prize in computing field for sure !! BIG RESPECT for you.

    Répondre
  • juin 11, 2021 à 4:57
    Permalien

    Code at 3:00. when i run first time it says "no data" as it should but when i click the submit button again without entering anything in text box it displays "data found". is this normal?

    Répondre
  • juin 11, 2021 à 4:57
    Permalien

    where you have put name="data", would this also work for value="Data"? my inputs already have names corresponding to what they are for?

    Répondre
  • juin 11, 2021 à 4:57
    Permalien

    Brad can you make a tutorial for sending and receiveinh email through contact form (PHPMailer etc.) please Brad. Thanks

    Répondre
  • juin 11, 2021 à 4:57
    Permalien

    this is the most understandable video i've seen about this topic. The holy grail of validation/sanitation-explaination.

    Répondre
  • juin 11, 2021 à 4:57
    Permalien

    Hi could anyone help here. 16:25 Travis has created an associative array and I've understood the keys are custom however the keys used in this example relates to actual properties. Does anyone know where I can find the list of properties that can be used with arrays? Thanks

    Répondre
  • juin 11, 2021 à 4:57
    Permalien

    Leaving the form action attribute blank or leaving it out altogether will produce a form that recalls itself.
    $_SERVER['PHP_SELF'] is useful in HTML 5 formaction attributes where the form's action has been set to a different file and one wants an option pointing back to the same file.

    Répondre
  • juin 11, 2021 à 4:57
    Permalien

    Does this filter_array thing need to have matching variable names?, Forgot to mention, thank you for the awesome video 🙂

    Répondre
  • juin 11, 2021 à 4:57
    Permalien

    the holy grail of php filter videos , i think this one its the most explanatory and easy to understand videos bout validations , thanks dude , you saved me

    Répondre
  • juin 11, 2021 à 4:57
    Permalien

    I think that regular if…else and nested if…else statement is more suitable than filter_input_array() function. In filter_input_array() you can't for example determine whether email field is empty or invalid where in if…else you can.

    Répondre
  • juin 11, 2021 à 4:57
    Permalien

    great vid, and series so far man – been doing php for about a decade now, and I'm picking stuff up – thanks!

    Répondre
  • juin 11, 2021 à 4:57
    Permalien

    For the future viewers that is having a hard time understanding the filter_input_array part

    that is to say this part >>

    $filters = array(

    "data" => FILTER_VALIDATE_EMAIL,

    "data2" => array(

    "filter" => FILTER_VALIDATE_INT,

    "options" => array(

    "min_range" => 1,

    "max_range" => 100,

    )

    )

    );

    The keys inside the "data2" the ""filter", "options" That is predefined by the filter_input_array function, so it is necessary that is the name of the key, it is not created by brad, as well as the "min_range" and "min_max" is necessary for this to work, if you change those keys, then this will not work as that key is necessary for the function filter_input_array

    more info here, https://www.php.net/manual/en/function.filter-input-array.php

    Répondre
  • juin 11, 2021 à 4:57
    Permalien

    at 8:56. , since you have already defined $email = filter_var($email,FILTER_SANITIZE_EMAIL) on line14, is it ok to just pass $email to line 17 ? tested and it worked, just not sure if is the best practice. thx

    Répondre
  • juin 11, 2021 à 4:57
    Permalien

    the problem these tutorials is that there is no conceptual explanation, no talk of how things actually work, just a stream of examples of this and that

    Répondre
  • juin 11, 2021 à 4:57
    Permalien

    How are you moving the cursor so rapidly? Are you using mouse or the arrow keys or some shortcuts?

    Répondre
  • juin 11, 2021 à 4:57
    Permalien

    Please reply to the doubts:

    The FILTER_SANITIZE_EMAIL does not remove #,$,* etc….Only removes / and

    Is this the case with someone else?

    Pls reply
    input:
    test//?\|||.><@test+==/*-.com

    output:
    test?|||.@test+==*-.com

    And what does the filter_input_array do?
    Anyone please reply

    Répondre
  • juin 11, 2021 à 4:57
    Permalien

    99:99 – HERE
    4:22 – FILTER_VALIDATE_EMAIL
    6:47 – FILTER_SANITIZE_EMAIL
    9:21 – other VALIDATION & SANITIZE
    11:48 – FILTER_SANITIZE_NUMBER_INT
    12:21 – FILTER_SANITIZE_SPECIAL_CHARS + filter_var () !!!
    17:00 – filter_input_array() , filter_var_array()

    Répondre

Laisser un commentaire