Advertisement
Guest User

Untitled

a guest
May 27th, 2017
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. <?PHP
  2. // variabili di connessione
  3. // nome server, nome utente,
  4. // Password, nomedatabase, tabella
  5. $ServerName = "localhost";
  6. $UserName = "root";
  7. $Password = "madara";
  8. $DbName = "EP";
  9. $tbl_name="studente";
  10.  
  11. // la connessione al database e alla tabella
  12. $conn = mysql_connect($ServerName, $UserName, $Password) or die("CONNECTION NON RIUSCITA");
  13. mysql_select_db($DbName, $conn);
  14. $nome = $_GET["nome"];
  15. $cognome = $_GET["cognome"];
  16. $universita=$_GET['universita'];
  17. $username = $_GET["username"];
  18. $password = $_GET["password"];
  19. $conferma=$_GET['conferma'];
  20. $email = $_GET["email"];
  21. $universita = $_GET["universita"];
  22.  
  23.  
  24. //Verifico il valore di $nome;
  25. if(chkEmail($email)) {
  26. if( (!empty($password)) and (!empty($conferma)) ){
  27. if( $password!=$conferma ) echo"<center>le password non corrispondono : ricontrolla i campi password</center>";
  28. else{
  29. if( (empty($nome)) or (empty($cognome)) or (empty($username)) )
  30. echo"<center>inserire tutti i campi è obbligatorio</center>";
  31. else{
  32. if( ($universita=="Salerno") or ($universita=="Londra") ){
  33. $MySql = "SELECT * FROM " . $tbl_name . " WHERE user_name='" . $username . "'";
  34. $Result = mysql_query($MySql,$conn) or die("Comunicazione al database fallita");
  35. $rs = mysql_fetch_array($Result);
  36. $a1 = $rs['user_name'];
  37. $a2 = $rs['email'];
  38. $rs->close;
  39. if($a1 == $username){
  40. die("Questo Nome utente gi&agrave esiste!");
  41. }
  42. $MySql2 = "SELECT * FROM " . $tbl_name . " WHERE e-mail='" . $email ."'";
  43. $Result2 = mysql_query($MySql2,$conn) or die("Comunicazione al database 2 fallita");
  44.  
  45. $rs2 = mysql_fetch_array($Result2);
  46. $a2 = $rs2['email'];
  47. $a3 = $rs2['user_name'];
  48. $rs->close;
  49. if($a2 == $email){
  50. die("Questa email &egrave gi&agrave stata usata dall'utente: $a3");
  51. }
  52. $password=(sha1(md5(sha1($password))));
  53. $query = "insert into " . $tbl_name. "(nome, cognome, user_name, password, e-mail, universita) VALUES ('$nome', '$cognome', '$username', '$password', '$email', '$universita')";
  54.  
  55.  
  56. $result=mysql_query($query,$conn); // result ci serve x fare il controllo
  57. var_dump($query); //sappiamo cosa ci restituisce la query
  58. if (!$result) die("errore registrazione");
  59. else echo "<center>".$nome ." ti sei iscritto, ora sei riconosciuto come ".$username."</center>";
  60. }
  61. else{
  62. if(empty($universita)) echo"<center>Spiacente se non inserisce la sua universit&agrave non pu&ograve proseguire</center>";
  63. else echo"<center>Spiacente la tua universit&agrave non fa parte del progetto European Platform </center>";
  64. }
  65. }
  66. }
  67. }
  68. else
  69. echo"<center>campi password non inseriti correttamente</center>";
  70. }
  71.  
  72.  
  73.  
  74. ?>
  75. <?php
  76.  
  77. function chkEmail($email)
  78. {
  79. // elimino spazi, "a capo" e altro alle estremità della stringa
  80. $email = trim($email);
  81. // se la stringa è vuota sicuramente non è una mail
  82. if(!$email) {
  83. return false;
  84. }
  85. // controllo che ci sia una sola @ nella stringa
  86. $num_at = count(explode( '@', $email )) - 1;
  87. if($num_at != 1) {
  88. return false;
  89. }
  90. // controllo la presenza di ulteriori caratteri "pericolosi":
  91. if(strpos($email,';') || strpos($email,',') || strpos($email,' ')) {
  92. return false;
  93. }
  94. // la stringa rispetta il formato classico di una mail?
  95. if(!preg_match( '/^[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}$/', $email)) {
  96. return false;
  97. }
  98. return true;
  99. }
  100.  
  101. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement