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
Discussions

php javascript alert redirect - Post.Byes - Bytes
hi all i want to show an alert box and then redirect page to another location through php code but its not working as needed. As i cannot use PHP HEADER LOCATION because i m using echo before header. so i have to use javascript but through PHP. if(mail($to,$subject,$body,$headers)) { echo " More on post.bytes.com
🌐 post.bytes.com
PHP : How to use alert() before header('location:http://domain.com');
You can do the header() function then within the next request that is probably called after the alert. ... This question is in a collective: a subcommunity defined by tags with relevant content and experts. ... Pausing the 1-rep voting experiment on Stack Overflow: reflecting on the... 8481 What does "use strict" do in JavaScript, and what is the reasoning behind it? 5099 Reference Guide: What does this symbol mean in PHP... More on stackoverflow.com
🌐 stackoverflow.com
javascript alert box not showing on php after header redirect - Stack Overflow
Explore Stack Internal ... Save this question. Show activity on this post. I am trying to display an alert box before redirecting to another page, here is my code, when I remove the header function it works properly but when it is here it will just redirect to the page without showing the alert box. Copy More on stackoverflow.com
🌐 stackoverflow.com
May 1, 2016
http redirect - JS alert not happening before php header/location change - Stack Overflow
This is an interesting one... I am trying to test for something, then show an alert then once the OK is clicked relocate the page to somewhere else, using header However if I have the code below i... More on stackoverflow.com
🌐 stackoverflow.com
🌐
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 ...