You could use Javascript:

// This is in the PHP file and sends a Javascript alert to the client
$message = "wrong answer";
echo "<script type='text/javascript'>alert('$message');</script>";
Answer from Peter Gluck on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › php › how-to-pop-an-alert-message-box-using-php
How to Pop an Alert Message Box using PHP? - GeeksforGeeks
July 12, 2025 - Program 1: PHP program to pop up an alert box on the screen. ... <?php // PHP program to pop an alert // message box on the screen // Display the alert box echo '<script>alert("Welcome to Geeks for Geeks")</script>'; ?>
🌐
Scaler
scaler.com › home › topics › php alert
PHP alert - Scaler Topics
April 1, 2024 - While PHP itself does not have ... client side. By generating JavaScript code within a PHP script, developers can trigger alert boxes and convey important messages to users interacting with web applications....
🌐
Edureka Community
edureka.co › home › community › categories › web development › php › how to show an alert box in php
How to show an alert box in PHP | Edureka Community
November 4, 2020 - I want to display an alert box showing a message with PHP. Here is my PHP code: But it is not working.
🌐
W3Schools
w3schools.com › howto › howto_js_alert.asp
How To Create an Alert Message Box
Alert messages can be used to notify the user about something special: danger, success, information or warning.
🌐
Simplilearn
simplilearn.com › home › resources › software development › alert in php: displaying an alert message box in php
Alert in PHP: Displaying An Alert Message Box in PHP
January 26, 2025 - Deep dive into alert in PHP tutorial and learn how to display an ⚠️ alert message box in PHP, types of pop-up boxes with examples. Start learning now!
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
STechies
stechies.com › display-alert-message-box-dialogue-box-using-php
How to Display Alert Message Box in PHP?
August 10, 2025 - <html> <head> <meta charset="utf-8"> <title>JavaScript Alert Box by PHP</title> <?php function_alert("We welcome the New World"); function function_alert($msg) { echo "<script type='text/javascript'>alert('$msg');</script>"; } ?> </head> <body> </body></html>
🌐
SitePoint
sitepoint.com › php
Php - alert box - PHP - SitePoint Forums | Web Development & Design Community
December 3, 2010 - Hi, I’ve looking for this on the web and haven’t found a clear explanation for my question. I have 2 pages, user select a story on the first page. Second page (using post method) receives the story value(there are only 3 options) and does something. If a user opens the second page without choosing a story, I want to pop an alert box saying user needs to choose a story first and redirect user to the first page. here is my php code $story = $_POST["stories"]; if (($story!= "story1.txt") && ...
Find elsewhere
🌐
W3Schools
w3schools.com › jsref › met_win_alert.asp
Window alert() Method
The alert() method displays an alert box with a message and an OK button.
🌐
Javatpoint
javatpoint.com › php-alert
PHP alert - javatpoint
PHP alert with examples, php file, php session, php date, php array, php form, functions, time, xml, ajax, php mysql, regex, string, oop, addslashes(), addcslashes() etc.
🌐
YouTube
youtube.com › watch
How to Open an alert message box using PHP - YouTube
Learn, How to open or pop up and alert message box using PHP. download source code and explore more? https://rathorji.in/p/how_to_open_an_alert_message_box_u...
Published   February 5, 2021
🌐
Naukri
naukri.com › code360 › library › php-alert
PHP Alert - Naukri Code 360
February 14, 2025 - Almost there... just a few more seconds
🌐
Delft Stack
delftstack.com › home › howto › php › php alert message
How to Alert Message Using PHP | Delft Stack
March 11, 2025 - This tutorial demonstrates different ways to show alert messages using PHP. Learn how to implement simple alerts, integrate with HTML forms, use session variables for persistent messages, and enhance user experience with SweetAlert. Discover effective techniques to improve feedback in your web applications.
🌐
Tpoint Tech
tpointtech.com › php-alert
PHP alert - Tpoint Tech
August 10, 2021 - In this article, we will learn about the use of dialog boxes of JavaScript i.e., the alert box, confirmation box, and prompt dialog box in PHP.
🌐
Medium
medium.com › @shahmarufsirajmugdho › how-to-use-alerts-in-php-7e5e637a7277
How to Use Alerts in PHP. Alerts are essential for user feedback… | by Shahmaruf Siraj Mugdho | Medium
September 6, 2024 - For modern, beautiful alerts, SweetAlert is the best solution. Here’s the optimal implementation: <?php include 'header.php'; echo '<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>'; ?> <?php function showSweetAlert($title, $message, $type = 'success', $redirect = '') { $script = "<script> Swal.fire({ title: '$title', text: '$message', icon: '$type', confirmButtonText: 'OK' })"; if (!empty($redirect)) { $script .= ".then(() => { window.location.href = '$redirect'; })"; } $script .= ";</script>"; echo $script; } // Usage example: showSweetAlert('Success!', 'Your data was saved', 'success', 'dashboard.php'); ?>