Advertisement
Guest User

Untitled

a guest
Dec 13th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. <?php
  2.  
  3. $ndni=$_REQUEST[dni];
  4.  
  5. $ldni=strlen($ndni);
  6. if($ldni>11){
  7. echo "La longitud maxima del dni son 11 cifras";
  8. }
  9. else{
  10. for($a=0;$a<=10;$a++){
  11. if($a%2){
  12. $acupar=0;
  13. $pares[] = substr($ndni,$a,1)*2;
  14.  
  15. }
  16. else{
  17. $impares[] = substr($ndni,$a,1);
  18.  
  19. }
  20.  
  21. }
  22. $acupar=0;
  23. for($p=0;$p<=10;$p++){
  24. $acupar=$acupar+$pares[$p];
  25. }
  26.  
  27.  
  28. $acuimpar=0;
  29. for($m=0;$m<=10;$m++){
  30. $acuimpar=$acuimpar+$impares[$m];
  31. }
  32.  
  33.  
  34. $sumatotal=$acupar+$acuimpar;
  35.  
  36. if($sumatotal%10){
  37. echo "Su DNI es correcto";
  38. }
  39. }
  40.  
  41.  
  42.  
  43.  
  44. ?>
  45.  
  46.  
  47.  
  48. <html>
  49. <form action="" method='post'>
  50. <p>DNI: <input type='text' name='dni'/></p>
  51. <p><input type='submit' name='enviar'></p>
  52. </form>
  53. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement