Advertisement
Guest User

Untitled

a guest
Jun 15th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.84 KB | None | 0 0
  1. <?php
  2. //Questa funzione aggiunge lo slash al carattere ' per rispettare la codifica del db
  3. function addbslash ($string)
  4. {
  5.     return str_replace ("'", "\'", $string);
  6. }
  7.  
  8. function chkmail ($e_mail)
  9. {
  10.     //pulisco la stringa
  11.     $e_mail = filter_var($e_mail, FILTER_SANITIZE_EMAIL);
  12.     return (filter_var($e_mail, FILTER_VALIDATE_EMAIL));
  13. }
  14. //--------------------------------------------------------------------------------------------
  15. session_start();
  16.  
  17. $name = addbslash($_POST['name']);
  18. $surname = addbslash($_POST['cognome']);
  19. $city = addbslash($_POST['città']);
  20. $prov = addbslash($_POST['provincia']);
  21. $adress = addbslash($_POST['indirizzo']);
  22. $phone = addbslash($_POST['telefono']);
  23. $email = addbslash($_POST['email']);
  24. $remail = addbslash($_POST['re-email']);
  25. $password = addbslash($_POST['password']);
  26. $repassword = addbslash($_POST['re-password']);
  27.  
  28.  
  29. //Se le mail sono diverse restituisco errore
  30. if (strcmp($email,$remail) != 0)
  31. {
  32.     $_SESSION['errore'] = "mail";
  33.     header("location:index.php?pag=big_error_frame");
  34.     break;
  35. }
  36. //Se le password sono diverse restituisco errore
  37. if (strcmp($password,$repassword) != 0)
  38. {
  39.     $_SESSION['errore'] = "password";
  40.     header("location:index.php?pag=big_error_frame");
  41.     break;
  42.  
  43. }
  44. if ( chkmail ($email) != true  && isset($_POST['registrati']))
  45. {
  46.     $_SESSION['errore'] = "formato";
  47.     header("location:index.php?pag=big_error_frame");
  48.     break;
  49.  
  50. }
  51. //Se è stato premuto il bottone annulla torno indietro
  52. if (isset($_POST['annulla']))
  53. {
  54.     header("location: index.php");
  55. }
  56.  
  57. //Se uno dei campi è nullo non permetto l'inserimento
  58. if ($name!=null && $surname!=null && $city!=null && $prov!=null && $adress!=null && $phone!=null && $email!=null && $password!=null && (isset($_POST['condizioni'])) && (isset($_POST['registrati'])))
  59. {
  60.     $conn = pg_connect("host=127.0.0.1 dbname=Sito user=tia password=mattiaroot19872009");
  61.     if (!$conn) echo ('Connessione fallita! <br />');
  62.  
  63.     $que = "select * from \"Utenti\" where email='$email'";
  64.     $que = utf8_encode ($que);
  65.    
  66.     //DA CAMBIARE!:D
  67.     $user = pg_query($que);
  68.     $row = pg_fetch_assoc($user, 0);
  69.  
  70.     if (strcmp($row['email'], $email) == 0)
  71.     {
  72.         $_SESSION['errore'] = "utente";
  73.         header("location:index.php?pag=big_error_frame");
  74.         break;
  75.     }
  76.  
  77.     $que = "insert into \"Utenti\"(id, nome, cognome, citta, provincia, indirizzo, email, pass, telefono, \"admin\") values (default,'$name', '$surname', '$city', '$prov', '$adress','$email','".md5($password)."', '$phone', false)";
  78.     $que = utf8_encode ($que);
  79.     $insert = pg_query($que);
  80.     if (!$insert)
  81.     {
  82.         $_SESSION['errore'] = "query";
  83.         header("location:index.php?pag=big_error_frame");
  84.     }
  85.     $_POST['registration'] = true;
  86.     header("location:index.php?pag=big_reg_ok_frame");
  87. }
  88. else
  89. {
  90.     if (isset($_POST['registrati']))
  91.     {
  92.         $_SESSION['errore'] = "campi";
  93.         header("location:index.php?pag=big_error_frame");
  94.     }
  95. }
  96.  
  97.  
  98. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement