register_send.php

Download Raw Clone


  1. <?php
  2. include 'config.php';
  3. include 'fungsi/base_url.php';
  4. if(isset($_POST['submit']))
  5. {
  6. $nama = mysqli_real_escape_string($conn,$_POST['nama']);
  7. $username = mysqli_real_escape_string($conn,$_POST['username']);
  8. $email = mysqli_real_escape_string($conn,$_POST['email']);
  9. $password = password_hash($_POST['password'], PASSWORD_DEFAULT);
  10. $telepon = mysqli_real_escape_string($conn,$_POST['telepon']);
  11. $alamat = mysqli_real_escape_string($conn,$_POST['alamat']);
  12. $kopos = mysqli_real_escape_string($conn,$_POST['kopos']);
  13. $prov = mysqli_real_escape_string($conn,$_POST['prov']);
  14. $kot = mysqli_real_escape_string($conn,$_POST['kot']);
  15. $kec = mysqli_real_escape_string($conn,$_POST['kec']);
  16. $sql = "SELECT * FROM customer WHERE email = '$email' and status = 1 ";
  17. $cek_email = mysqli_query($conn,$sql);
  18. if(empty($nama))
  19. {
  20. echo "<script>alert('Nama harus diisi!');history.go(-1)</script>";
  21. }
  22. elseif(empty($username))
  23. {
  24. echo "<script>alert('Username harus diisi!');history.go(-1)</script>";
  25. }
  26. elseif(empty($email))
  27. {
  28. echo "<script>alert('email harus diisi!');history.go(-1)</script>";
  29. }
  30. elseif(empty($password))
  31. {
  32. echo "<script>alert('password harus diisi!');history.go(-1)</script>";
  33. }
  34. elseif(empty($telepon))
  35. {
  36. echo "<script>alert('telepon harus diisi!');history.go(-1)</script>";
  37. }
  38. elseif(mysqli_num_rows($cek_email) > 0)
  39. {
  40. // Alert/ pemberitahuan email yang dipakai telah ada/ tidak
  41. echo "<script>alert('Email telah terpakai, silahkan gunakan email yang lain!');history.go(-1)</script>";
  42. }
  43. else
  44. {
  45. // Membuat kode unik untuk aktivasi akun dengan format md5
  46. $hash = md5(uniqid(rand(), true));
  47. // Subject: Judul pada email penerima
  48. $subject = 'Aktivasi akun Anda di namatoko.com';
  49. // Headers: Email pengirim, veri mime, dan jenis halaman
  50. $headers = "From: [email protected] \r\n";
  51. $headers .= "MIME-Version: 1.0\r\n";
  52. $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
  53. // url: Membuat teks yang apabila di klik oleh user, maka akan masuk ke halaman aktivasi akun pada website
  54. $url = $base_url.'activation.php?email='.urlencode($email)."&hash=$hash";
  55. // message: Isi pesan dari email
  56. $message = "<p>Silahkan klik tombol dibawah ini untuk mengaktifkan akun Anda di namatoko.com</p>";
  57. $message .= "<table cellspacing='0' cellpadding='0'> <tr>";
  58. $message .= "<td align='center' width='300' height='40' bgcolor='#000091' style='-webkit-border-radius: 5px; -moz-border-radius: 5px; border-radius: 5px;
  59. color: #ffffff; display: block;'>";
  60. $message .= "<a href='".$url."' style='color: #ffffff; font-size:16px; font-weight: bold; font-family: Helvetica, Arial, sans-serif; text-decoration: none;
  61. line-height:40px; width:100%; display:inline-block'>KLIK DISINI</a>";
  62. $message .= "</td></tr></table>";
  63. // Menjalankan fungsi mail dari php
  64. mail($email, $subject, $message, $headers);
  65. // Proses insert data customer
  66. $create = "INSERT INTO customer ( nama,
  67. username,
  68. email,
  69. password,
  70. telepon,
  71. alamat,
  72. kopos,
  73. provinsi,
  74. kota,
  75. kecamatan,
  76. hash,
  77. status)
  78. VALUES ('$nama',
  79. '$username',
  80. '$email',
  81. '$password',
  82. '$telepon',
  83. '$alamat',
  84. '$kopos',
  85. '$prov',
  86. '$kot',
  87. '$kec',
  88. '$hash',
  89. '0')";
  90. if (mysqli_query($conn, $create))
  91. {
  92. echo "<script>alert('Registrasi berhasil! Silahkan cek email Anda untuk verifikasi');location.replace('$base_url')</script>";
  93. }
  94. else
  95. {
  96. echo "Error updating record: " . mysqli_error($conn);
  97. }
  98. }
  99. }
  100. ?>

Raw paste data: