KOSUNI KOREA
Korean News in English
Technology

Implementing Login and Board Permission Management in PHP

Published October 17, 2026 · 1 views
Implementing Login and Board Permission Management in PHP

[PHP 강의] PHP 8.4 웹 프로그래밍 강의를 시작하며 – 초보도 끝까지 완주할 수 있는 실전 강의


Why Login Functionality Is Needed for Boards

The bulletin board created so far allows anyone to freely write, edit, or delete posts.

However, this isn't how real services operate.

For example:

  • Only registered members can post

  • Only the author can edit their posts

  • Only the author can delete their posts

  • Only administrators can delete all posts

User permissions vary accordingly.

In this lesson, we'll implement these permission management features.


Creating the Member Table

First, create a table to store member information.

CREATE TABLE member (

    id INT AUTO_INCREMENT PRIMARY KEY,

    userid VARCHAR(50) UNIQUE NOT NULL,

    password VARCHAR(255) NOT NULL,

    name VARCHAR(50) NOT NULL,

    is_admin TINYINT(1) DEFAULT 0,

    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP

);

The password field stores encrypted passwords.


Creating the Registration Page

Registration is implemented similarly to the bulletin board using a form.

<form action="register_ok.php" method="post">

아이디

<input type="text" name="userid">

이름

<input type="text" name="name">

비밀번호

<input type="password" name="password">

<button>

회원가입

</button>

</form>


Passwords Must Be Encrypted

Storing passwords in plain text is extremely dangerous.

Never store them like this:

1234

Or like this:

password

In practice, passwords must always be encrypted before storage.


Using password_hash()

PHP makes it easy to encrypt passwords.

<?php

$password = password_hash(

    $_POST["password"],

    PASSWORD_DEFAULT

);

Now the database stores encrypted strings.


Saving Member Data

<?php

$sql = "

INSERT INTO member

(userid, password, name)

VALUES

(?, ?, ?)

";

$stmt = $pdo->prepare($sql);

$stmt->execute([

$_POST["userid"],

$password,

$_POST["name"]

]);

Registration is complete.


Login Page

<form action="login_ok.php" method="post">

아이디

<input type="text" name="userid">

비밀번호

<input type="password" name="password">

<button>

로그인

</button>

</form>


Fetching Member Data

Retrieve member information using the ID.

<?php

$stmt = $pdo->prepare(

"SELECT * 

FROM member

WHERE userid=?"

);

$stmt->execute([

$_POST["userid"]

]);

$user = $stmt->fetch();


Verifying Passwords with password_verify()

Check if the entered password matches.

<?php

if (

password_verify(

$_POST["password"],

$user["password"]

)

) {

echo "로그인 성공";

}

This is the most commonly used method in practice.


Storing Session After Successful Login

<?php

session_start();

$_SESSION["user_id"] =

$user["id"];

$_SESSION["userid"] =

$user["userid"];

$_SESSION["name"] =

$user["name"];

Now the login state is maintained.


Checking Login Status

<?php

session_start();

if (

!isset($_SESSION["user_id"])

) {

exit("로그인이 필요합니다.");

}

This is commonly used on member-only pages.


Logging Out

<?php

session_start();

session_destroy();

header("Location:index.php");

Destroying the session logs you out.


Post Writing Permissions

On the post writing page, first check if the user is logged in.

<?php

if (

!isset($_SESSION["user_id"])

) {

exit("로그인 후 이용 가능합니다.");

}

Non-members cannot write posts.


Storing Author Information

When saving a post, store the logged-in member's ID along with it.

<?php

$stmt->execute([

$_POST["title"],

$_POST["content"],

$_SESSION["user_id"]

]);

Now we can identify who wrote each post.


Only Authors Can Edit

<?php

if (

$post["user_id"]

!=

$_SESSION["user_id"]

) {

exit("수정 권한이 없습니다.");

}

Users cannot edit others' posts.


Only Authors Can Delete

Deletion works similarly.

<?php

if (

$post["user_id"]

!=

$_SESSION["user_id"]

) {

exit("삭제 권한이 없습니다.");

}


Implementing Admin Permissions

Since the member table includes an is_admin column, implementing admin permissions is straightforward.

<?php

if (

$_SESSION["is_admin"]

== 1

) {

echo "관리자입니다.";

}


Admins Can Delete All Posts

<?php

if (

$post["user_id"]

==

$_SESSION["user_id"]

||

$_SESSION["is_admin"]

==1

)

{

echo "삭제 가능";

}

Administrators can manage all posts.


Adjusting Menu Based on Login Status

The menu changes based on login status.

<?php

if (

isset($_SESSION["user_id"])

) {

echo "로그아웃";

}
else {

echo "로그인";

}

Real websites implement this similarly.


Displaying Author Information

Show the author on the list page as well.

<?php

echo $row["name"];

Or like this:

홍길동

2026-07-03

To display the author's name and date.


Hiding Buttons for Non-Logged In Users

<?php

if (

isset($_SESSION["user_id"])

) {

echo "<a href='write.php'>글쓰기</a>";

}

Non-logged in users won't see the write button.


Common Beginner Mistakes

When implementing login features, beginners often make these mistakes:

  • Not encrypting passwords

  • Not using password_verify()

  • Forgetting to write session_start()

  • Not checking login status

  • Implementing edit features without author verification

  • Ignoring admin permissions

Focusing on these points will make your bulletin board much more secure.


How It's Implemented in Real Projects

In actual projects, this structure is commonly used:

login.php

↓

login_ok.php

↓

Session creation

↓

Board usage

↓

Logout

Member permissions are managed using sessions.


Features Completed in This Lesson

After this lesson, you'll be able to implement these features:

  • Registration

  • Login

  • Logout

  • Session maintenance

  • Member-only posting

  • Author-only editing

  • Author-only deletion

  • Admin permissions

Your bulletin board will now closely resemble a real service.


In Conclusion

This lesson covered implementing login functionality and board permission management.

Login is one of the most important features on websites, and permission handling directly relates to security.

Specifically, using password_hash(), password_verify(), and session-based login are the most common methods used in PHP practice—so be sure to master these techniques.

In the next lesson, we'll finish this project by completing the bulletin board, applying security measures, deploying to a server, and operating it as a fully functional PHP bulletin board system.

FAQ

Why should passwords be encrypted in a database?

Storing plain text passwords is extremely dangerous as it allows attackers to easily compromise user accounts if the database is breached. Encryption protects user credentials even if unauthorized access occurs.

What is the purpose of session_start() in PHP?

session_start() initializes a session, allowing data to be stored and retrieved across multiple pages during a single user's visit. It's essential for maintaining login state without requiring users to log in repeatedly on each page.

Korean Source

This article is an English localization of a Korean-language report from BlogScore. Original: [PHP 강좌] 11강 로그인 기능과 게시판 권한 처리하기