"iceking" <iceking_e<nospam>@yahoo.com> wrote in
news:41***********************@news.xs4all.nl:
Hi,
I have a php script that checks whether the user is allowed to perform
an action. If he is not allowed; I display a warning; using the alert
function. After clicking away this function, I want to redirect the
user to the original page using the header function.
However, I get the normal message " headers already sent"... I know
what the problem is.
But how do you normally deal with this situation? use a html/php for
the warning instead of alert message? or is there another way?
i have built this php function which does exactly what you want - create
a javascript warning, and direct them to a new page when they click 'ok':
<?php
function popup($vMsg,$vDestination) {
echo("<html>\n");
echo("<head>\n");
echo("<title>System Message</title>\n");
echo("<meta http-equiv=\"Content-Type\" content=\"text/html;
charset=iso-8859-1\">\n");
echo("<script language=\"JavaScript\" type=\"text/JavaScript\">\n");
echo("alert('$vMsg');\n");
echo("window.location = ('$vDestination');\n");
echo("</script>\n");
echo("</head>\n");
echo("<body>\n");
echo("</body>\n");
echo("</html>\n");
exit;
}
?>
So, you call it like this:
<?php
//they made an error
popup('Hey, you made a mistake, jackass.','retry.php');
?>