I'm seeing a problem that has me flummoxed. The only thing I can
think of is that I'm violating some rule I don't know about.
I have some code that does some processing and then does a
header('Locatio n: ...) jump to page A on success or falls through to
the jump to page B. This is the code:
if ( mysql_query( 'LOCK TABLES tableX WRITE', $link ) )
{
mysql_query( $q, $link ) ; // store the record
$ID = mysql_insert_id ( $link ) ; // save the new id
if ( mysql_affected_ rows($link) == 1 )
{
unlock_tables() ;
$_SESSION['ErrMsg'] = 'New ID is ' . $ID ;
header( 'Location: PageA.php' ) ;
$_SESSION['ErrMsg'] .= ' Error: ignored jump' ;
}
else // the store failed
{ error handling }
}
// second chance (for debugging) to do the right thing
header( 'Location: PageA.php' ) ;
$_SESSION['ErrMsg'] .= ' and it ignored it AGAIN!' ;
// and we shouldn't get here at all -- but we do!
header( 'Location: PageB.php ) ;
Unfortunately, as I know from the telltales I stuff into session, the
store works but the interpreter ignores both header calls that would
jump to A and finally jumps to B instead. Unless I'm more tired than
I'm aware, or more ignorant, this doesn't make sense.
Any straw gratefully clutched.
Margaret
--
(To mail me, please change .not.invalid to .net, first.
Apologies for the inconvenience.) 10 5666
If you display anything by the script first (such as echo 'hello
world<br>';) the header won't redirect after that.
Margaret MacDonald wrote: I'm seeing a problem that has me flummoxed. The only thing I can think of is that I'm violating some rule I don't know about.
I have some code that does some processing and then does a header('Locatio n: ...) jump to page A on success or falls through to the jump to page B. This is the code:
if ( mysql_query( 'LOCK TABLES tableX WRITE', $link ) ) { mysql_query( $q, $link ) ; // store the record $ID = mysql_insert_id ( $link ) ; // save the new id
if ( mysql_affected_ rows($link) == 1 ) { unlock_tables() ; $_SESSION['ErrMsg'] = 'New ID is ' . $ID ; header( 'Location: PageA.php' ) ; $_SESSION['ErrMsg'] .= ' Error: ignored jump' ; } else // the store failed { error handling } } // second chance (for debugging) to do the right thing header( 'Location: PageA.php' ) ; $_SESSION['ErrMsg'] .= ' and it ignored it AGAIN!' ;
// and we shouldn't get here at all -- but we do! header( 'Location: PageB.php ) ;
Unfortunately, as I know from the telltales I stuff into session, the store works but the interpreter ignores both header calls that would jump to A and finally jumps to B instead. Unless I'm more tired than I'm aware, or more ignorant, this doesn't make sense.
Any straw gratefully clutched.
Margaret
PagCal wrote: If you display anything by the script first (such as echo 'hello world<br>';) the header won't redirect after that.
Thanks for your quick response.
In this case, that's not a problem. Since I don't do any i/o it
actually does redirect. The problem is that it ignores the
redirection I expect!
Margaret MacDonald wrote: I'm seeing a problem that has me flummoxed. The only thing I can think of is that I'm violating some rule I don't know about.
I have some code that does some processing and then does a header('Locatio n: ...) jump to page A on success or falls through to the jump to page B. This is the code:
if ( mysql_query( 'LOCK TABLES tableX WRITE', $link ) ) { mysql_query( $q, $link ) ; // store the record $ID = mysql_insert_id ( $link ) ; // save the new id
if ( mysql_affected_ rows($link) == 1 ) { unlock_tables() ; $_SESSION['ErrMsg'] = 'New ID is ' . $ID ; header( 'Location: PageA.php' ) ; $_SESSION['ErrMsg'] .= ' Error: ignored jump' ; } else // the store failed { error handling } } // second chance (for debugging) to do the right thing header( 'Location: PageA.php' ) ; $_SESSION['ErrMsg'] .= ' and it ignored it AGAIN!' ;
// and we shouldn't get here at all -- but we do! header( 'Location: PageB.php ) ;
Unfortunately, as I know from the telltales I stuff into session, the store works but the interpreter ignores both header calls that would jump to A and finally jumps to B instead. Unless I'm more tired than I'm aware, or more ignorant, this doesn't make sense.
Any straw gratefully clutched.
Margaret
--
(To mail me, please change .not.invalid to .net, first.
Apologies for the inconvenience.)
On Tue, 03 Aug 2004 12:25:04 GMT, Margaret MacDonald
<sc**********@a tt.not.invalid> wrote: I'm seeing a problem that has me flummoxed. The only thing I can think of is that I'm violating some rule I don't know about.
I have some code that does some processing and then does a header('Locati on: ...) jump to page A on success or falls through to the jump to page B. This is the code:
if ( mysql_query( 'LOCK TABLES tableX WRITE', $link ) ) { mysql_query( $q, $link ) ; // store the record $ID = mysql_insert_id ( $link ) ; // save the new id
if ( mysql_affected_ rows($link) == 1 ) { unlock_tables() ; $_SESSION['ErrMsg'] = 'New ID is ' . $ID ; header( 'Location: PageA.php' ) ; $_SESSION['ErrMsg'] .= ' Error: ignored jump' ; } else // the store failed { error handling } } // second chance (for debugging) to do the right thing header( 'Location: PageA.php' ) ; $_SESSION['ErrMsg'] .= ' and it ignored it AGAIN!' ;
// and we shouldn't get here at all -- but we do! header( 'Location: PageB.php ) ;
Unfortunatel y, as I know from the telltales I stuff into session, the store works but the interpreter ignores both header calls that would jump to A and finally jumps to B instead. Unless I'm more tired than I'm aware, or more ignorant, this doesn't make sense.
From the manual entry for header():
<quote>
The optional replace parameter indicates whether the header should
replace a previous similar header, or add a second header of the same
type. By default it will replace, but if you pass in FALSE as the
second argument you can force multiple headers of the same type.
</quote>
This suggests that your last header() call to redirect to B is
replacing your previous redirects to A.
Put an exit() after your header() to force the script to terminate.
--
David ( @priz.co.uk )
Margaret MacDonald wrote: I'm seeing a problem that has me flummoxed. The only thing I can think of is that I'm violating some rule I don't know about.
Actually yes, that is what is happening.
I have some code that does some processing and then does a header('Locatio n: ...) jump to page A on success or falls through to the jump to page B. This is the code:
Analyzing a few snippets of your code:
if ( mysql_query( 'LOCK TABLES tableX WRITE', $link ) ) { mysql_query( $q, $link ) ; // store the record $ID = mysql_insert_id ( $link ) ; // save the new id
if ( mysql_affected_ rows($link) == 1 ) { unlock_tables() ; $_SESSION['ErrMsg'] = 'New ID is ' . $ID ; header( 'Location: PageA.php' ) ;
Here you set the header to PageA.php. It is set correctly as it should.
However, since you dont tell the script to exit(), the script continues
running.
$_SESSION['ErrMsg'] .= ' Error: ignored jump' ; } else // the store failed { error handling } } // second chance (for debugging) to do the right thing header( 'Location: PageA.php' ) ;
Now you set the same header again. still, the script keeps running.
$_SESSION['ErrMsg'] .= ' and it ignored it AGAIN!' ;
// and we shouldn't get here at all -- but we do! header( 'Location: PageB.php ) ;
Now you set the same header third time. By default setting the same
header again replaces the header, as it should. There is a way to force
php to send the same header more than once, although that is usually not
very smart, especially with the location-header.
Now that the script execution ends, the headers are sent, and the
location header points to the last one you set it to, PageB.php.
What you propably want to do is to add exit(); after each all three
header calls and you should be fine.
HTH
--
Suni
Just a sidenote:
The just released PHP5 contains a function headers_list() that would
have made debugging your problem very easy.
--
Suni
Juha Suni wrote: Margaret MacDonald wrote: I'm seeing a problem that has me flummoxed. The only thing I can think of is that I'm violating some rule I don't know about. Actually yes, that is what is happening.
I have some code that does some processing and then does a header('Locatio n: ...) jump to page A on success or falls through to the jump to page B. This is the code:
Analyzing a few snippets of your code:
if ( mysql_query( 'LOCK TABLES tableX WRITE', $link ) ) { mysql_query( $q, $link ) ; // store the record $ID = mysql_insert_id ( $link ) ; // save the new id
if ( mysql_affected_ rows($link) == 1 ) { unlock_tables() ; $_SESSION['ErrMsg'] = 'New ID is ' . $ID ; header( 'Location: PageA.php' ) ;
Here you set the header to PageA.php. It is set correctly as it should. However, since you dont tell the script to exit(), the script continues running.
aaaAAAAAaaaaa! *THAT* was the piece I was missing. I thought (don't
ask me why) the header call with a location argument was the actual
jump.
As Mark Twain didn't quite say, it's not our ignorance but our
meta-ignorance that will get us, every time.
Thank you very much for deconfusing me. $_SESSION['ErrMsg'] .= ' Error: ignored jump' ; } else // the store failed { error handling } } // second chance (for debugging) to do the right thing header( 'Location: PageA.php' ) ;
Now you set the same header again. still, the script keeps running.
$_SESSION['ErrMsg'] .= ' and it ignored it AGAIN!' ;
// and we shouldn't get here at all -- but we do! header( 'Location: PageB.php ) ;
Now you set the same header third time. By default setting the same header again replaces the header, as it should. There is a way to force php to send the same header more than once, although that is usually not very smart, especially with the location-header.
Now that the script execution ends, the headers are sent, and the location header points to the last one you set it to, PageB.php.
What you propably want to do is to add exit(); after each all three header calls and you should be fine.
HTH
--
(To mail me, please change .not.invalid to .net, first.
Apologies for the inconvenience.)
David Mackenzie wrote: On Tue, 03 Aug 2004 12:25:04 GMT, Margaret MacDonald <sc**********@ att.not.invalid > wrote:
I'm seeing a problem that has me flummoxed. The only thing I can think of is that I'm violating some rule I don't know about.
I have some code that does some processing and then does a header('Locat ion: ...) jump to page A on success or falls through to the jump to page B. This is the code:
if ( mysql_query( 'LOCK TABLES tableX WRITE', $link ) ) { mysql_query( $q, $link ) ; // store the record $ID = mysql_insert_id ( $link ) ; // save the new id
if ( mysql_affected_ rows($link) == 1 ) { unlock_tables() ; $_SESSION['ErrMsg'] = 'New ID is ' . $ID ; header( 'Location: PageA.php' ) ; $_SESSION['ErrMsg'] .= ' Error: ignored jump' ; } else // the store failed { error handling } } // second chance (for debugging) to do the right thing header( 'Location: PageA.php' ) ; $_SESSION['ErrMsg'] .= ' and it ignored it AGAIN!' ;
// and we shouldn't get here at all -- but we do! header( 'Location: PageB.php ) ;
Unfortunately , as I know from the telltales I stuff into session, the store works but the interpreter ignores both header calls that would jump to A and finally jumps to B instead. Unless I'm more tired than I'm aware, or more ignorant, this doesn't make sense.
From the manual entry for header():
<quote> The optional replace parameter indicates whether the header should replace a previous similar header, or add a second header of the same type. By default it will replace, but if you pass in FALSE as the second argument you can force multiple headers of the same type. </quote>
This suggests that your last header() call to redirect to B is replacing your previous redirects to A.
Put an exit() after your header() to force the script to terminate.
Thanks, David. It's the 'put an exit() after your header()' part that
I was missing. I didn't understand that that call to header doesn't
terminate execution...and since the 20 other cases where I make a
similar call are working correctly purely by accident.... :-}
Margaret
--
(To mail me, please change .not.invalid to .net, first.
Apologies for the inconvenience.)
.oO(Juha Suni) Margaret MacDonald wrote:
header( 'Location: PageA.php' ) ;
Here you set the header to PageA.php. It is set correctly as it should.
Nope, it's _not_ set correctly (even if it's not the real problem in
this case). The location-header requires an absolute URL including the
scheme ( http://) and hostname. Most browsers also accept the "short"
version, but it's broken and not standards-compliant.
Micha
Michael Fesser wrote: .oO(Juha Suni)
Margaret MacDonald wrote:
header( 'Location: PageA.php' ) ;
Here you set the header to PageA.php. It is set correctly as it should.
Nope, it's _not_ set correctly (even if it's not the real problem in this case). The location-header requires an absolute URL including the scheme (http://) and hostname. Most browsers also accept the "short" version, but it's broken and not standards-compliant.
Yes indeed, I meant to mention that in my post too, but forgot. Thanks
for the correction. Many people tend to use relative urls for location
header, where they would propably be better of with a custom function or
use of an included config file that would specify the "root-url" and add
the specified relative url to that for the header call.
for example:
function relative_redire ct($relurl) {
$rooturl = 'http://www.mysite.com. invalid/mydir/';
// possibly add a if file_exists()-check for local
// redirections for easier debugging and/or exception handling
header('Locatio n: ' . $rooturl . $relurl);
exit();
}
--
Suni This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Filth |
last post by:
Hi
this is probably very easy to sort but I want to do the following:-
header( "Location:
subscribe_form.php?name='.$_GET.'&email='.$_GET.'");
but this pulls up the error:-
Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting
|
by: Stephen Preston |
last post by:
I have a split frame which holds in the upper part a php file with a header
location function, which opens a new file (lower.php). I'm trying to get
the header function to open lower.php in the lower half of the frame,
header("Location: lower.php TARGET='lowframe')
with out the Target setting, it opens lower.php in the upper part (ie it
replaces its self), but with the TARGET statement it can't find the file.
Is this do able? or is...
|
by: lwoods |
last post by:
I am trying to pass some info to another page on my site. I set
"session_start()" in page 1, assign a session variable to a value, then
execute a "header('Location: ....')." But on the target page I don't get
any session variable values! BTW, I used a relative location in the
Location header, not an absolute URL. The behavior looks like it started
another session, but it should not have.
Ideas?
TIA,
|
by: Ladbroke |
last post by:
Hiya,
got a little prob with the syntax for
header ( ' Location .... with variable).
Usually examples are given with a complete URL, like:
..... header( 'Location: login/testsite/start.php' );
I'd like to use particular read out data from my database (URL)
(variable $result).
|
by: P-Rage |
last post by:
Hello everyone,
I was wondering what could possibly cause Internet Explorer 6 to loop a
page usging a header(Location:) statement.
For example, a page called 'page1.php':
if((isset($_POST)) && ($name='valid')){
// insert some data into MySQL.
| |
by: geshan |
last post by:
In php5 I am not able to use include funciton and header("location:"""
together please help.
|
by: pedalpete |
last post by:
I thought this should be simple, but i can't seem to get it to work.
I'm trying to do a simple redirect to a page, but need to pass a variable.
I've tried a few things, but nothing seems to work.
here's what I've tried
header('Location: edit.php?sid=$sid');
|
by: luv737 |
last post by:
Hello All,
I need some help here! My company decided to jump from Version 4.2 of PHP to the current release 5.2.9-2 as well as move from apache to IIS on Windows 2003. Of course we are running into all types of problems but for some reason the Header Location logic that use to work no longer works. It just hangs out there. I am not sure if there is a configuration problem or some type of enhancement to PHP but I have been unable to resolve...
|
by: sedigh mohseni |
last post by:
hi
I write a simple script for test header statement.I expect my script show a warning message and dont transmit to another page but unfortunately, i am transmited to another page.
my question is this, is there any setting in php.ini that is related with blank space that is sent to the browser before header statement .
my experimental script is as follow as:
<?php
ini_set("error_reporting", E_ALL);
ini_set("display_errors", "on");
|
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,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| |