473,651 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 5902
*** 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="<?=htmlsp ecialchars($pre vious_page)?>"> Return</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<nosp am>@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,$vD estination) {
echo("<html>\n" );
echo("<head>\n" );
echo("<title>Sy stem Message</title>\n");
echo("<meta http-equiv=\"Content-Type\" content=\"text/html;
charset=iso-8859-1\">\n");

echo("<script language=\"Java Script\" type=\"text/JavaScript\">\n ");
echo("alert('$v Msg');\n");
echo("window.lo cation = ('$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.','retr y.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.hr ef= "url";

-Charles
"Rainmaker" <Ra************ @SPAMhotmail.co m> wrote in message
news:7J******** ***********@ams news05.chello.c om...
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
3347
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. The purpose of the code is simply to delete a record and then redirect back to the page where the delete was started. The code looks like this: elseif ($_GET == "delete") { $query = "delete from product_subcategory2 where product_sku=$_GET and...
7
15912
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 type="text/javascript"> window.location = "http://www.someserver.com/somePage.html"; </script>
6
4316
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 serves two purposes, 1. it contains a tab strip with response.redirects to navigate to the other pages; 2. I authenticate the user by check to see if a cookie exists, if it doesn't I redirect to a login screen.
8
24264
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 been sent like If response.IsSentHttpHeader then ....
4
11425
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 XMLHTTP object. However, when the page requested through the XML object makes a <%Response.Redirect()%> call, a new session is created each time. Is this a flaw in the XMLHTTP Object? How can I force the session to remain the same after a...
7
13440
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 checked require secure channel, require 128-bit encryption. In custom error, instead of using default message HTTP 403.4 - Forbidden: SSL required Internet Information Services in iishelp 403.4htm, I am trying to do redirect automatically. so I...
5
3235
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 allow me to do this? Thanks, Kevin
18
2661
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: is supposed to take a fully qualified URL.
1
7280
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 and Brand I need to make some changes on a a number of brands in a Category
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8795
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8460
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6157
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4281
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2696
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1906
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.