Академический Документы
Профессиональный Документы
Культура Документы
);;
mysql_query($create)
or die (Could not create tables because .mysql_error());
echo Mantap!!sekarang lanjut deh ke tahap yang ketiga;
?>
3. Sekarang anda perlu membuat form yang digunakan pengunjung untuk
sign up dan berikan nama register.html. File yang anda buat ini boleh
berupa halaman HTML biasa yang nantinya akan terhubung pada script php
yang nantinya anda akan buat. Untuk percobaan yang sederhana, anda
dapat mengkopi script di bawah pada halaman baru dreamweaver .
<html><head>
<title>User Registration</title>
</head><body>
<form action=register.php method=post>
Pick a Username: <input type=text name=username size=20><br>
Pick a Password: <input type=password name=password
size=20><br>
<input type=submit value=Sign Up>
</form>
</body></html>
4. Setelah itu buat file dengan nama register.php. File ini akan berfungsi
sebagai perantara yang menghubungkan file register.html diatas dengan
database yang sudah anda buat. Untuk isi dari file register.php" dapat
anda lihat dibawah.
<?php
include(config.php);
// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die (Could not connect to mysql because .mysql_error());
// select the database
mysql_select_db($database)
or die (Could not select database because .mysql_error());
// check if the username is taken
$check = select id from $table where username = .
$_POST['username'].;;
$qry = mysql_query($check) or die (Could not match data because
.mysql_error());
$num_rows = mysql_num_rows($qry);
if ($num_rows != 0) {
echo Maaf ye, username $username sudah keduluan diambil orang.<br>;
$num_rows = mysql_num_rows($qry);
if ($num_rows <= 0) {
echo Sorry, there is no username $username with the specified
password.<br>;
echo <a href=login.html>Try again</a>;
exit;
} else {
setcookie(loggedin, TRUE, time()+(3600 * 24));
setcookie(mysite_username, $username);
echo You are now logged in!<br>;
echo Continue to the <a href=members.php>members</a> section.;
}
?>
7. perhatikan file tersebut pad baris ketiga paling bawah, disana berisi <a
href=members.php> members.php ini adalah sebuah area yang hanya
bisa dilihat oleh para member.
Anda dapat membuat file members.php dengan kreasi sendiri.
Sekarang saya akan menjelaskan script yang digunakan untuk mengecek
cookie, apakah orang tersebut sudah login atau tidak. Simpan scipt ini di
seluruh area members. Scriptnya sbb;
<?php if (!isset($_COOKIE['loggedin'])) die(You are not logged in!
log in);
$mysite_username = $HTTP_COOKIE_VARS["mysite_username"];
echo you are logged in as $mysite_username.
; ?>
8. script yang terakhir yaitu script untuk logout. Script ini dapat dihubungkan
dengan link pada html biasa. Link ini diletakkan pada area member. Untuk isi
scriptnya dapat anda lihat sbb:
<?php
// expire cookie
setcookie (loggedin, , time() - 3600);
echo You are now logged out.<br>;
echo <a href=\login.html\>Log in</a>.;
?>