Advertisement
Guest User

Php Form Validation & Security

a guest
Jul 21st, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.98 KB | None | 0 0
  1. <?php
  2.     if($_SERVER["REQUEST_METHOD"] == "POST"){
  3.        
  4.         $fullName = test_input($_POST['fullname']);
  5.         $Email = test_input($_POST['email']);
  6.         $userName = test_input($_POST['username']);
  7.         $passWord = test_input(sha1($_POST['password']));
  8.        
  9.         echo $fullName . "<br />" . $Email . "<br />" . $userName . "<br />" . $passWord . "<br />";
  10.        
  11.         if(filter_var($Email,FILTER_VALIDATE_EMAIL)){
  12.            
  13.             echo 'your email is valid ' . '<br />';
  14.            
  15.         }else{
  16.            
  17.             echo 'your email is not valid : try again'  . '<br />';
  18.            
  19.         }
  20.        
  21.         if(preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/',$fullName)){
  22.            
  23.             echo 'bad full name input ';
  24.            
  25.         }
  26.         else{
  27.            
  28.             echo 'good full name input ';          
  29.         }
  30.     }
  31.    
  32.     function test_input($inputField){
  33.        
  34.         $inputField = htmlspecialchars(stripcslashes(strip_tags($inputField)));
  35.         return $inputField;
  36.        
  37.     }
  38.    
  39. ?>
  40.  
  41. <html>
  42.     <head>
  43.         <meta charset='UTF-8'>
  44.         <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  45.     </head>
  46. <body>
  47.    
  48.     <form action="<?php htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
  49.     <h1>CodeJs : Input Validation </h1>
  50.        
  51.         <div class="form-group">
  52.             <label>Full Name:</label>
  53.             <input type="text" class="form-control" name='fullname'>
  54.         </div>
  55.        
  56.         <div class="form-group">
  57.             <label>Email address:</label>
  58.             <input type="text" class="form-control" name='email'>
  59.         </div>
  60.        
  61.         <div class="form-group">
  62.             <label>Username :</label>
  63.             <input type="text" class="form-control" name='username'>
  64.         </div>
  65.        
  66.         <div class="form-group">
  67.             <label>Password:</label>
  68.             <input type="text" class="form-control" name='password'>
  69.         </div>
  70.        
  71.         <button type="submit" class="btn btn-default">Submit</button>
  72.     </form>
  73.    
  74. <style>form{ width: 400px; margin-left: 350px; }</style>
  75. <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  76. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  77. </body>
  78. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement