You're doing an echo and then writing a relocate header. If you did your relocate in the javascript (after the user clicked the alert), it would probably work the way you expect it to.

echo "<script>alert('You are logged out'); window.location.href='..\Main.php';</script>";

Also, the way that you use isset will cause problems because isset returns true or false (it checks if a value is present), rather than returning the value.

So instead of

if(isset($_SESSION['Username']) == "admin")

You need to do:

if(isset($_SESSION['Username']) && $_SESSION['Username'] == "admin") 
Answer from Steve K on Stack Overflow
🌐
LinuxQuestions.org
linuxquestions.org › questions › programming-9 › alert-box-in-php-won't-work-4175685817
Alert Box in PHP won't work
November 25, 2020 - This code produces "blank". How can I make it work? Code: msg=dbCheck(database); // check if db exists if(substr(msg, 0,2)!="OK"
🌐
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.
🌐
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 - Using this you can alert to the user with some information and message. PHP doesn't support alert message box because it is a server-side language but you can use JavaScript code within the PHP body to alert the message box on the screen.
🌐
SitePoint
sitepoint.com › php
Php - alert box - PHP - SitePoint Forums | Web Development & Design Community
December 3, 2010 - $story = $_POST["stories"]; if (($story!= "story1.txt") && ($story!="story2.txt") && ( $story!="story3.txt")){ echo'<script>alert("You need to choose a story first, please go to Story Selection");window.location.href= "StorySelection.php";</script>'; } this is what i figured out from other posts This code does not work, I just see bunch of question marks.
🌐
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
🌐
Scaler
scaler.com › home › topics › php alert
PHP alert - Scaler Topics
April 1, 2024 - Alert in php is not inherently available as it is in other programming languages like JavaScript. PHP is primarily a server-side scripting language used for processing data and generating dynamic web content.
Find elsewhere
🌐
STechies
stechies.com › display-alert-message-box-dialogue-box-using-php
How to Display Alert Message Box in PHP?
<html> <head> <meta charset="utf-8"> <title>JavaScript Alert Box by PHP</title> <?php echo '<script type="text/javascript">'; echo ' alert("JavaScript Alert Box by PHP")'; //not showing an alert box.
🌐
X
freeonlineprojects.com › alert-message-and-page-redirect-not-working-inside-php
Alert Message and Page Redirect Not Working Inside PHP
JavaScript is not available · We’ve detected that JavaScript is disabled in this browser. Please enable JavaScript or switch to a supported browser to continue using x.com. You can see a list of supported browsers in our Help Center · Help Center · Terms of Service Privacy Policy Cookie ...
🌐
Post.Byes
post.bytes.com › home › forum › topic › php
php javascript alert redirect - Post.Byes - Bytes
so if this is true then alert should popup first before the PHP Header redirect. you're mixing up server code and browser code. first, all of the server code is executed (i.e the redirect via header()), afterwards, all browser code is executed (i.e. show the popup via alert()). ... Or the popup is not working because we are generating alert popup through PHP.
🌐
PHP
php.net › manual › en › function.error-reporting.php
PHP: error_reporting - Manual
If you just see a blank page instead of an error reporting and you have no server access so you can't edit php configuration files like php.ini try this: - create a new file in which you include the faulty script: <?php error_reporting(E_ALL); ...
🌐
Stack Overflow
stackoverflow.com › questions › 16592457 › alert-message-wont-display
php - alert message won't display - Stack Overflow
May 24, 2017 - You would never see that alert even if it did work. Secondly - come on, javascript alerts? Just write the messages out to the html. ... Hint: The statement alert('You didn't fill all fields!'); contains three apostrophes. ... That's because of the row .. ... Try this one instead .. ... What you did wrong was that you had an apostrophe in the string and around the string. I don't know how to explain this but I simply made the two quotation marks to not conflict with the php echo.