473,386 Members | 2,078 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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
Jul 17 '05 #1
6 5884
*** 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)?>">Retur n</a></p>

(Is is necessary to crosspost?)

--
-- Álvaro G. Vicario - Burgos, Spain
-- Thank you for not e-mailing me your questions
--
Jul 17 '05 #2
"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 confused:

-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

Jul 17 '05 #3
Excellent answer tot my problem!
Of course it is server side <-> clientside
Now I use the location.href for redirection after clicking away the
message....

I should have known this..... ;-o

Thanks
"Daniel Tryba" <ne****************@canopus.nl> wrote in message
news:ci*********@news.tue.nl...
"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 confused:

-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

Jul 17 '05 #4
"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');

?>
Jul 17 '05 #5
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.
Jul 17 '05 #6
If using a javascript ALERT, try using a javascript redirection... ie:
top.location.href= "url";

-Charles
"Rainmaker" <Ra************@SPAMhotmail.com> wrote in message
news:7J*******************@amsnews05.chello.com...
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.

Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Steve | last post by:
I just spent waaaaaaaaaaaayy too much time trying to track down an error that was incorrectly reported just now, and I would like to see if someone can explain to me why it was reported that way. ...
7
by: Donna Hawkins | last post by:
I want to use javascript to redirect to a URL which has been passed as a variable (in php). I have searched but cannot find any solution. I think this code is a basic redirect: <script...
6
by: Sam | last post by:
I have some issues with HTTP Headers and I was hoping for some pointers or references to good articles. Here is the problem. I have 6 .aspx pages, each page contains a common .ascx. This ascx...
8
by: Andreas Klemt | last post by:
Hello, I get this error Message "cannot redirect after http headers have been sent" when I do this response.redirect ("home.aspx") How can I find out with vb.net if already a http header has...
4
by: mike.biang | last post by:
I have an ASP page that is using an XMLHTTP object to request various pages from my server. I keep a single session throughout the XMLHTTP requests by bassing the ASPSESSIONID cookie through the...
7
by: =?Utf-8?B?YzY3NjIyOA==?= | last post by:
Hi all, I am trying to set this up using asp code and IIS configuration. But it seems not working. Here it is the way I am doing. In IIS I set up a virtual directory with secure communication, I...
5
by: Kevin Audleman | last post by:
I understand how to use the header command to redirect a page before any HTML has been loaded.However, I need to redirect after some HTML has already been loaded. is there a command that will...
18
by: Paul Lautman | last post by:
JRough wrote: What do you mean by "redirect the output to Excel"??? Excel isn't a location, it's a spreadsheet program that some (but not all users) will have on their machine. BTW, Location:...
1
by: gnawz | last post by:
Hi guys, I have a couple of php files that perform various tasks. I will use fields in my system and provide code as well I need help as follows: My database contains the fields Category...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.