Advertisement
reyxnardo

register_send.php

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