Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2018
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.56 KB | None | 0 0
  1. <?php
  2.  
  3. // Importing DBConfig.php file.
  4. include 'DBConfig.php';
  5.  
  6.    
  7. // Creating connection.
  8.  $con = mysqli_connect($HostName,$HostUser,$HostPass,$DatabaseName);
  9.  
  10.  // Getting the received JSON into $json variable.
  11.  $json = file_get_contents('php://input');
  12.  
  13.  // decoding the received JSON and store into $obj variable.
  14.  $obj = json_decode($json,true);
  15.  
  16. $ime=$obj['imee'];
  17. $prez=$obj['prezz'];
  18. $email = $obj['email'];
  19. $password = $obj['password'];
  20. $code = md5(uniqid(rand()));
  21.  
  22.  
  23. //Checking Email is already exist or not using SQL query.
  24. $CheckSQL = "SELECT * FROM user WHERE username='$email'";
  25.  
  26. // Executing SQL Query.
  27. $check = mysqli_fetch_array(mysqli_query($con,$CheckSQL));
  28.  
  29.  
  30. if(isset($check)){
  31.  
  32.  $EmailExistMSG = 'Email Already Exist, Please Try Again !!!';
  33.  
  34.  // Converting the message into JSON format.
  35. $EmailExistJson = json_encode($EmailExistMSG);
  36.  
  37. // Echo the message.
  38.  echo $EmailExistJson ;
  39.  
  40.  }
  41.  
  42.  else{
  43.  
  44.  // Creating SQL query and insert the record into MySQL database table.
  45. $Sql_Query = "insert into user (name,lastname,username,password,token,userStatus) values ('$ime','$prez','$email','$password','$code','N')";
  46.  
  47.  
  48.  if(mysqli_query($con,$Sql_Query)){
  49.  
  50.  // If the record inserted successfully then show the message.
  51.  
  52.  
  53. $MSG = 'User Registered Successfully' ;
  54.  
  55.  
  56.     $message = "                   
  57.                         Pozdrav $name,
  58.                         <br /><br />
  59.                         Dobrodosli u Kvisko!<br/>
  60.                         Da biste dovšili registraciju potrebno je da kliknete na link ispod!<br/>
  61.                         <br /><br />
  62.                         <strong><a href='http://vucko.x3.rs/dev-sajt/kvisko/verify.php?code=$code'>Kliknite ovde za aktivaciju</a></strong>
  63.                         <br /><br />
  64.                         Hvala,";
  65.                        
  66.             $subject = "Registracija korisnika";
  67.                        
  68.         require_once('mailer/class.phpmailer.php');
  69.         $mail = new PHPMailer();
  70.         $mail->IsSMTP();
  71.         $mail->SMTPDebug = 0;
  72.         $mail->SMTPAuth   = true;                  
  73.         $mail->SMTPSecure = "tls";                
  74.         $mail->Host       = "smtp.gmail.com";      
  75.         $mail->Port       = 587;            
  76.         $mail->AddAddress($email);
  77.         $mail->Username="miloszv94@gmail.com";  
  78.         $mail->Password="Vuckovic94";            
  79.         $mail->SetFrom('miloszv94@gmail.com','Kvisko');
  80.         $mail->AddReplyTo("miloszv94@gmail.com","Kvisko");
  81.         $mail->Subject    = $subject;
  82.         $mail->MsgHTML($message);
  83.         $mail->Send();
  84.  
  85. // Converting the message into JSON format.
  86. $json = json_encode($MSG);
  87.  
  88. // Echo the message.
  89.  
  90.  echo $json ;
  91.  
  92.  }
  93.  else{
  94.      $MSG = 'NIej bas' ;
  95.  $json = json_encode($MSG);
  96.   echo $json ;
  97.  //echo 'Try Again';
  98.  
  99.  }
  100.  }
  101.  mysqli_close($con);
  102. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement