Created
January 6, 2022 01:21
-
-
Save erowsika/5da1e3925917ad3293dfc76518b75a3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// simpan fungsi ini di mana kek. contoh di arspi/helpers.php | |
// trus panggil ki di setiap pemanggilan echo | |
if (! function_exists('e')) { | |
function e($value, $doubleEncode = true) | |
{ | |
return htmlspecialchars($value ?? '', ENT_QUOTES, 'UTF-8', $doubleEncode); | |
} | |
} | |
// contoh pemanggilan echo di index.php | |
?> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Document</title> | |
</head> | |
<body> | |
<table> | |
<tr>No</tr> | |
<td>Nama</td> | |
<td>Username</td> | |
<?php | |
$con = mysqli_connect("localhost", "username", "password", "dbname"); | |
// file login.php | |
require_once(__DIR__ . '/helpers.php'); | |
// check if the user id and password combination exist in database | |
$sql = mysqli_query($con, "SELECT * FROM users"); | |
$i = 0; | |
while ($record = mysqli_fetch_array($result)) { | |
?> | |
<tr> | |
<td><?php echo $no; // ini tidak di bungkus karena yg pake ini itu developer karena developer jelas mau nya apa ?></td> | |
<td><?php echo e($record['nama']); // di setiap pemanggilan echo bungkus dulu dengan fungsi e alias htmlspecialchars ?></td> | |
<td><?php echo e($record['username']); ?></td> | |
<?php | |
// kenapa $record dibungkus e trus $no tidak pake ? | |
// karena $record itu data dari database yang di input oleh user yang dimana | |
// klw jebol login mu, user bisa isi inputan nya dengan menyisipkan script javascript, | |
// dimana itu adalah XSS yang target nya itu mendapatkan cookie, | |
// klw cookie mu di ambil bisa ko pake cookie nya orang tanpa login, | |
// trus juga setiap website yg pernah ko login akan punya cookie, | |
// dan cookie tersebut menjadi rentan di pake oleh si penjobol tersebut | |
// jadi toh ini fungsi e adalah lapisan keamanan output | |
// sedangkan lapisan keamanan input itu adalah pake fungsi mysqli_escape_string | |
?> | |
</tr> | |
<?php $no++; ?> | |
<?php } ?> | |
</table> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment