Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to Sanitize Email ID and URL in PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 232
    Comment on it

    Hello Everyone, today I will guide you "To Sanitize a String in PHP"

    SANITIZE :- Data affirmation is usually an inclusive element of working with varieties. Not merely may be published files result in protection problems, nevertheless additionally, it may bust your current webpage. Today, we are going to consider the best way to take away against the law personas in addition to verify files using the "filter_var" functionality.

    In simple words Sanitizing will remove any illegal character from the data.

    Below code defines if user can fill the Email ID with some special character like (example)@///\gmail.com and Website URL like http://example^^^^.com, the Sanitizing will remove the extra content.

    <?php
    
        if(isset($_POST['submit'])){
    
           if (isset($_POST['email'])) {
            echo filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
          }
    
          if (isset($_POST['website'])) {
              echo filter_var($_POST['website'], FILTER_SANITIZE_URL);
          }
    
        }
    
    ?>
    
    <form name="form1" method="post">
        Email ID: <br/>
        <input type="text" name="email" value="<?php echo $_POST['email']; ?>"/> <br/><br/>
        Website URL: <br/>
        <input type="text" name="website" value="<?php echo $_POST['website']; ?>"/> <br/>
        <br/>
        <input type="submit" name="submit" value="Save" />
    </form>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: