Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

How to redirect after (header) after sending an alert message
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



Report this thread to moderator Post Follow-up to this message
Old Post
iceking
09-16-04 09:52 AM


Re: How to redirect after (header) after sending an alert 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
--

Report this thread to moderator Post Follow-up to this message
Old Post
Alvaro G Vicario
09-16-04 09:52 AM


Re: How to redirect after (header) after sending an alert 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


Report this thread to moderator Post Follow-up to this message
Old Post
Daniel Tryba
09-16-04 09:52 AM


Re: How to redirect after (header) after sending an alert 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');

?>

Report this thread to moderator Post Follow-up to this message
Old Post
Good Man
09-17-04 01:32 AM


Re: How to redirect after (header) after sending an alert message
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 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.

Report this thread to moderator Post Follow-up to this message
Old Post
Rainmaker
09-20-04 02:00 PM


Re: How to redirect after (header) after sending an alert message
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 
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.
>



Report this thread to moderator Post Follow-up to this message
Old Post
Charles Pelkey
09-27-04 01:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP Language archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:12 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.