PHP Login Guide for BIyyy Server

Summary

This announcement on BIyyy's server community provides a basic PHP guide for implementing a user login system. It details the necessary code snippets for the login form, a protected welcome page, and a logout function using sessions. This guide is intended to help users set up fundamental authentication, though it stresses the need for further security enhancements in real applications.

Login

Login

$error

"; } ?> Username:

Password:

Login

**4. Halaman Selamat Datang (welcome.php)**

Halaman ini hanya bisa diakses jika sudah login.

```php
<?php
session_start();

if (!isset($_SESSION['username'])) {
    header("Location: login.php"); // Redirect jika belum login
    exit();
}

$username = $_SESSION['username'];
?>

<!DOCTYPE html>
<html>
<head>
    <title>Welcome</title>
</head>
<body>
    <h2>Selamat Datang, <?php echo $username; ?>!</h2>
    <a href="logout.php">Logout</a>
</body>
</html>

5. Logout (logout.php)

Untuk menghapus session dan mengarahkan kembali ke halaman login.

<?php
session_start();
session_destroy();
header("Location: login.php");
exit();
?>

Penting:

  • Jangan lupa ganti username_mysql dan password_mysql dengan informasi yang benar.
  • Untuk menyimpan password di database, gunakan fungsi password_hash() saat mendaftarkan user baru. Contoh: $hashed_password = password_hash($password, PASSWORD_DEFAULT);
  • Kode ini masih sangat sederhana. Untuk aplikasi yang lebih serius, perlu ditambahkan validasi input, proteksi terhadap XSS, dan lain-lain.

Semoga ini membantu! Kalau ada pertanyaan, jangan ragu untuk bertanya. 😊

15 views

The latest from BIyyy's server

BIyyy Weekly Quest Champions Announced

The BIyyy's server community has announced the champions for this week's quest competition. @Gaming is the Quest Champion, achieving the top rank with 5 points. …

Join BIyyy Weekly Competition — Win Rewards

BIyyy's server community is announcing the start of a weekly competition where members can win rewards by completing quests. The competition resets every Monday UTC, …

Weekly Server Quests — Win Rewards Now

BIyyy's server is launching weekly server quests to encourage member participation and offer rewards. Members can complete these quests, which reset every Monday UTC, to …

Add Social Media Links to Toko Buket Pink

The announcement on BIyyy's server community provides detailed instructions on how to add social media links to the "Toko Buket Pink" website. This includes adding …

Tambahkan Ikon Instagram & TikTok ke Footer

The announcement on BIyyy's server details instructions for adding Instagram and TikTok icons to the website's footer. This involves adding specific HTML code to the …