Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this message*** 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 functio n. > 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 --
Post Follow-up to this message"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 functio n. > 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
Post Follow-up to this message"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');
?>
Post Follow-up to this messageiceking <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 functio n. > 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.
Post Follow-up to this messageIf 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 function. what > > 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. >
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.