Home > Archive > PHP Language > September 2004 > How to redirect after (header) after sending an alert message
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How to redirect after (header) after sending an alert message
|
|
| iceking 2004-09-16, 4:52 am |
| 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?
Thanks
| |
| Alvaro G Vicario 2004-09-16, 4:52 am |
| *** iceking wrote/escribió (Thu, 16 Sep 2004 10:07:37 +0200):
> 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?
There's no point in displaying info for the user at the same time you're
redirecting the user out of the page where that info is.
Unless you have very specific needs I can't see a reason to avoid Really
Simple Solutions:
<p>Action not allowed</p>
<p><a href="<?=htmlspecialchars($previous_page)?>">Return</a></p>
(Is is necessary to crosspost?)
--
-- Álvaro G. Vicario - Burgos, Spain
-- Thank you for not e-mailing me your questions
--
| |
| Daniel Tryba 2004-09-16, 4:52 am |
| "iceking" <iceking_e <nospam>@yahoo.com> wrote:
> 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.
You are :
-the alert function is clientside javascript
-header is serverside php
These can't work together in the way you describe above since by the
time the alert gets to the client, the php script is long gone.
The solution you might be looking for is the javascript location.href
property...
--
Daniel Tryba
| |
| Good Man 2004-09-16, 8:32 pm |
| "iceking" <iceking_e<nospam>@yahoo.com> wrote in
news:41494a1f$0$48933$e4fe514c@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');
?>
| |
| Rainmaker 2004-09-20, 9:00 am |
| iceking <iceking_e wrote:
> 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?
>
>
> Thanks
>
>
Although it has no real use to send headers after your output, as
mentioned in the other posts, you can use
http://nl2.php.net/manual/en/function.ob-start.php ob_start if you
really want to. Dirty solution btw. Better not use it.
| |
| Charles Pelkey 2004-09-26, 8:55 pm |
| If using a javascript ALERT, try using a javascript redirection... ie:
top.location.href= "url";
-Charles
"Rainmaker" <Rainmaker526NO@SPAMhotmail.com> wrote in message
news:7Jy3d.104657$C7.79323@amsnews05.chello.com...
> iceking <iceking_e wrote:
an[color=darkred]
function.[color=darkred]
what[color=darkred]
>
> Although it has no real use to send headers after your output, as
> mentioned in the other posts, you can use
> http://nl2.php.net/manual/en/function.ob-start.php ob_start if you
> really want to. Dirty solution btw. Better not use it.
>
|
|
|
|
|