forked from ihsanfaisal/kota-kecamatan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdaftar.php
83 lines (62 loc) · 3.24 KB
/
daftar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
require_once('konfigurasi.php');
$message = '';
if ($_POST) {
if ($_POST['email'] != '') {
$username = $_POST['username'];
$sth = $koneksidb->prepare("SELECT * FROM pengguna WHERE username='$username'");
$sth->execute();
$baris = $sth->rowCount(); //untuk mendapatkan jumlah baris hasil query
if ($baris > 0) {
/*
* jika jumlah baris yang username nya dari $_POST lebih
* tampilkan pesan bahwa username telah digunakan/ada
*
*/
echo "username sudah digunakan silahkan coba yang lain.";
exit;
} else {
$ip = $_SERVER["REMOTE_ADDR"];
$email = $_POST['email'];
$kode = md5(rand());
$query = "INSERT INTO `pengguna` (`nama`, `username`, `password`, `email`, `alamat`, `remote_ip`, `kode_konfirmasi`) VALUES ('{$_POST['nama']}', '{$_POST['username']}', '{$_POST['password']}', '$email', '{$_POST['alamat']}', '$ip', '$kode')";
$koneksidb->exec($query);
$body = "<!DOCTYPE html>
<html>
<head>
<title>Aktifkan akun anda!</title>
</head>
<body>
<div class='container'>
<div class='jumbotron'>
<h1>Aktifkan akun anda!</h1>
<p class='lead'>Hi $username, Tinggal satu langkah lagi anda melengkapi pendaftaran ini.!</p>
<p><a class='btn btn-lg btn-success' href='$url/konfirmasi_user.php?kode=$kode' role='button'>Aktifkan Sekarang!</a></p>
</div>
<div class='footer'>
<p>© Kota Kecamatan 2014</p>
</div>
</div> <!-- /container -->
</body>
</html>";
$mail->IsSMTP();
$mail->Host = "localhost";
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "[email protected]";
$mail->Password = "kota-kecamatan";
$mail->SetFrom('kotakecamatan', 'Kota Kecamatan');
$mail->Subject = "Aktifkan akun anda!";
$mail->MsgHTML($body);
$address = "$email";
$mail->AddAddress($address, "");
$mail->Send();
$_SESSION['info_berhasildaftar'] = "Registrasi berhasil dilakukan. Email konfirmasi telah dikirim kepada $email.\nSilahkan konfirmasi email anda";
header('Location: daftar.berhasil.php');
exit;
}
}
}
header('Location: index.php');