Advertisement
Guest User

php

a guest
Apr 28th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. <?php
  2. include_once "koneksi.php";
  3.  
  4. class usr{}
  5.  
  6. $username = $_POST["username"];
  7. $password = $_POST["password"];
  8. $confirm_password = $_POST["confirm_password"];
  9. $profil = $_POST["profil"];
  10. $info = $_POST["info"];
  11. $nama_admin= $_POST["nama_admin"];
  12.  
  13.  
  14.  
  15. if ((empty($username))) {
  16. $response = new usr();
  17. $response->success = 0;
  18. $response->message = "Kolom username tidak boleh kosong";
  19. die(json_encode($response));
  20. } else if ((empty($password))) {
  21. $response = new usr();
  22. $response->success = 0;
  23. $response->message = "Kolom password tidak boleh kosong";
  24. die(json_encode($response));
  25. } else if ((empty($confirm_password)) || $password != $confirm_password) {
  26. $response = new usr();
  27. $response->success = 0;
  28. $response->message = "Konfirmasi password tidak sama";
  29. die(json_encode($response));
  30. } else if((empty($profil))){
  31. $response = new usr();
  32. $response->success = 0;
  33. $response->message = "Tolong tambahkan foto profil";
  34. die(json_encode($response));
  35. }else if((empty($info))){
  36. $response = new usr();
  37. $response->success = 0;
  38. $response->message = "Tolong deskripsikan diri kamu";
  39. die(json_encode($response));
  40. }else if((empty($nama_admin))){
  41. $response = new usr();
  42. $response->success = 0;
  43. $response->message = "Tolong deskripsikan diri kamu";
  44. die(json_encode($response));
  45. }else {
  46. if (!empty($username) && $password == $confirm_password){
  47. $num_rows = mysqli_num_rows(mysqli_query($conn, "SELECT * FROM akun WHERE username='".$username."'"));
  48.  
  49. if ($num_rows == 0){
  50.  
  51. $random = random_word(20);
  52.  
  53. $path = "ikon/".$random.".png";
  54. $actualpath = "http://192.***1/meme/$path";
  55. $query = mysqli_query($conn, "INSERT INTO akun (id_akun, username, password, nama_admin, deskripsi, ikon) VALUES(NULL,'".$username."','".$password."','".$nama_admin."','".$info."','".$actualpath."')");
  56.  
  57. if ($query){
  58. file_put_contents($path,base64_decode($profil));
  59. $response = new usr();
  60. $response->success = 1;
  61. $response->message = "Register berhasil, silahkan login.";
  62. die(json_encode($response));
  63.  
  64. } else {
  65. $response = new usr();
  66. $response->success = 0;
  67. $response->message = "Username sudah ada";
  68. die(json_encode($response));
  69. }
  70. } else {
  71. $response = new usr();
  72. $response->success = 0;
  73. $response->message = "Username sudah ada";
  74. die(json_encode($response));
  75. }
  76. }
  77. }
  78. // fungsi random string pada gambar untuk menghindari nama file yang sama
  79. function random_word($id = 20){
  80. $pool = '1234567890abcdefghijkmnpqrstuvwxyz';
  81.  
  82. $word = '';
  83. for ($i = 0; $i < $id; $i++){
  84. $word .= substr($pool, mt_rand(0, strlen($pool) -1), 1);
  85. }
  86. return $word;
  87. }
  88. mysqli_close($conn);
  89.  
  90. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement