Maybe try redirect using JavaScript.

if ( user_id == 0) {
    $message = 'This is a message.';

    echo "<SCRIPT> //not showing me this
        alert('$message')
        window.location.replace('url of the page');
    </SCRIPT>";
    mysql_close();
}
Answer from Zander Rootman on Stack Overflow
🌐
GitHub
gist.github.com › ErMandeep › 6faea4751b7f388c94651dd811933dc0
display alert message after redirecting page php · GitHub
display alert message after redirecting page php. GitHub Gist: instantly share code, notes, and snippets.
🌐
DaniWeb
daniweb.com › programming › web-development › threads › 487676 › getting-header-error-when-generating-alert-messsage
php - Getting header error when generating Alert ... [SOLVED] | DaniWeb
November 18, 2014 - PHP will not know if javascript already alerted the user. To redirect using the PHP redirect function a simple javascript function is needed to call a PHP function, ... Thanks but I worked it out (with some help from the nice people at The Code Of A Ninja). This is what I did. I Changed · // check if the item is in the array, if it is, do not add if(array_key_exists($id, $_SESSION['cart_items'])){ // redirect to product list and tell the user it was added to cart header('Location: ../sale_barn_yearlings_test2.php#'.$id.''); echo '<script language="javascript">'; echo 'alert("item alredy in sh
🌐
Post.Byes
post.bytes.com › home › forum › topic › php
php javascript alert redirect - Post.Byes - Bytes
hi Dormilich i have heard that javascript works on client side and works faster than server side scripts. so if this is true then alert should popup first before the PHP Header redirect. Or the popup is not working because we are generating alert popup through PHP. vineet You should never rely on JS to be enabled client side. There is no reason for it to be faster, but it often misbehaves client side (broken browsers or it's disabled) which isn't worth the few CPU cycles you save on the server. Also, go read about ob_start() in the PHP documentation.
🌐
WebDeveloper.com
webdeveloper.com › community › 217839-how-do-i-add-a-msg-box-alert-before-changing-header
How do i?.. Add a msg box alert before changing header.
Copy linkTweet thisAlerts: @opifexOct 07.2009 — #ok. since you have the option to redirect OR show a thank you message already.... replace this [code=php]header ("Location:$location");[/code] with this [code=php] echo "<script type="text/javascript">n"; echo "alert('Thank you for submitting our form.');n"); echo "window.location = ('$location');n"; echo "</script>";[/code] ... Ok thanks for the help but i thought about it and instead what i did was make the link to the contact us page open a new window then after the form was submited i made it redirect the window to a page with thank you on it and a close window button so i kinda took a easy way out.
Find elsewhere
🌐
Talkerscode
talkerscode.com › howto › alert-in-php-and-redirect.php
Alert In PHP And Redirect
In which <?php is our opening tag and ?> is our closing tag. Here, as we see that to alert a message we use alert() function with the help of jQuery. In first case, we use script inside echo and then alert inside that.
🌐
CopyProgramming
copyprogramming.com › howto › javascript-alert-and-php-header
Php: Header redirection using PHP and triggering alerts with Javascript
June 6, 2023 - After conducting extensive research, I discovered a solution that involves delaying the alert message using a jQuery function. This delay enables the HTML page to load completely before the alert is executed. ... I am facing an issue with my PHP script. It works fine without a header, and I ...
🌐
PHP
php.net › manual › en › function.header.php
PHP: header - Manual
If you want to redirect an user and tell him he will be redirected, e. g. "You will be redirected in about 5 secs. If not, click here." you cannot use header( 'Location: ...' ) as you can't sent any output before the headers are sent.
🌐
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 ...
🌐
Javaer101
javaer101.com › en › article › 34192710.html
PHP how to echo alert before header redirects to another page - Javaer101
PHP's redirection with header("Location:xxx.php"); functionality does not allow any browser output. You can use Javascript redirection (taking in consideration of program logic). echo '<script> alert(' + '"Welcome ' + $uname .'"); window.location.href="welcome.php"; </script>'; Collected from the Internet ·