Your greeting displays in a centered card-like panel with a light background and drop shadow.
<?php
declare(strict_types=1);
// Load file contents safely
$file = 'flatfile.txt';
if (!file_exists($file)) {
$randPhrase = "Welcome! (No greetings found)";
} else {
$lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
if (!$lines) {
$randPhrase = "Welcome! (Greeting list is empty)";
} else {
// More secure random selection
$randPhrase = $lines[random_int(0, count($lines) - 1)];
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Random Greeting</title>
<style>
body {
font-family: system-ui, sans-serif;
background: #f7f7fb;
display: flex;
height: 100vh;
align-items: center;
justify-content: center;
margin: 0;
}
.greeting-box {
background: white;
padding: 40px 50px;
border-radius: 12px;
box-shadow: 0 8px 20px rgba(0,0,0,0.08);
font-size: 28px;
color: #333;
text-align: center;
}
</style>
</head>
<body>
<div class="greeting-box">
<?= htmlspecialchars($randPhrase, ENT_QUOTES, 'UTF-8'); ?>
</div>
</body>
</html>Open notepad and add a few lines:
Hello and Welcome!
Hi how are you today?
Hey there, what you doin?
Save as: flatfile.txt
Article discussion
Share your thoughts about this article.
Log in or create an account to comment.
No comments yet. Be the first to join the discussion.