why header("location") doesn't work?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

mesutsahin
Forum Newbie
Posts: 10
Joined: Wed Feb 08, 2006 3:14 am

why header("location") doesn't work?

Post by mesutsahin »

We have an e-commercial web site and we should redirect our customers to a result page according to the response of the bank.
Although there is no error message, header("location:xxxx.php"); doesn't work in any browser.
Also this code works for other banks perfect without any error.
But for one bank it doesn't work without any error.

Some php.ini configuration:
display_errors:on
output_buffering:on

Code: Select all

if($approved==true){
      header("location:".HTTPS_SERVER."/successful.php");
      exit();
}
else{
     header("location:".HTTPS_SERVER."/fail.php");
     exit();
}
after sending form with that bank, this code is just doing exit() by skipping header("locaiton") row.
Thank you for your help.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Is HTTPS_SERVER a defined constant? Is it correct?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

I am guessing here...

1. Perhaps that server doesn't support redirects.
2. Perhaps one of the files was saved in a format (eg dos) or uploaded in binary which is causing it to output data so it can't send the redirect because the header was already sent.
3. Perhaps one of the files were corrupted when uploaded.
4. Perhaps the one particular web site is using a different url scheme. (eg http://domainname.com instead of http://www.domainname.com)
User avatar
quocbao
Forum Commoner
Posts: 59
Joined: Sat Feb 04, 2006 2:03 am
Location: HCM,Vietnam
Contact:

Post by quocbao »

and perhap your browser disable redirect :)

Try other browser
User avatar
khaki_monster
Forum Commoner
Posts: 73
Joined: Tue Oct 11, 2005 12:36 am
Location: Philippines
Contact:

Post by khaki_monster »

HI!

i once had problems regarding with Header() function, but tanx for this forum i was able to solved it.
here's the origenal('Links') question that i throw before:
viewtopic.php?t=43784

and this was the given example that solved my problem.
viewtopic.php?t=1157
feyd actually give me this link :) thanx man!
hope this may help a bit...

cheerz!
mesutsahin
Forum Newbie
Posts: 10
Joined: Wed Feb 08, 2006 3:14 am

header location doesn't work

Post by mesutsahin »

1. Perhaps that server doesn't support redirects.
2. Perhaps one of the files was saved in a format (eg dos) or uploaded in binary which is causing it to output data so it can't send the redirect because the header was already sent.
3. Perhaps one of the files were corrupted when uploaded.
4. Perhaps the one particular web site is using a different url scheme.

1.server supports redirects. Because it works for other banks.
2.All files have php extension
3.no, they are not corrupted. We have checked them.
4. url scheme http://www.zzzzzzzzzzzzzzz.com

If the headers are already sent, php would show an error. In my ini configuration display error = on
It doesn't show any error.
User avatar
quocbao
Forum Commoner
Posts: 59
Joined: Sat Feb 04, 2006 2:03 am
Location: HCM,Vietnam
Contact:

Post by quocbao »

as i said : try other browser

I met this problem once when i used FireFox and when i tested it with IE it worked fine

be careful , because you can also disable location header in IE so be sure to enable it ;) maybe Tools -> Internet Options -> Advanced -> Enable page transition
mesutsahin
Forum Newbie
Posts: 10
Joined: Wed Feb 08, 2006 3:14 am

Post by mesutsahin »

I am trying with all browsers including(IE,Netscape,Firefox,Opera).
It works on the server side. I don't think it's about the browser.
It makes no sense that I have made the settings in my browser.
How can I tell all the customers to change the browser settings.
User avatar
quocbao
Forum Commoner
Posts: 59
Joined: Sat Feb 04, 2006 2:03 am
Location: HCM,Vietnam
Contact:

Post by quocbao »

It makes no sense that I have made the settings in my browser.
How can I tell all the customers to change the browser settings.
Opps , as a web developer , browser is important . Maybe your website work 100% on IE but when using FF or other browsers they may work only 80-90% ( design interface , javascript , css , etc ... )

If you don't want to change your browser setting , then you can use this

Code: Select all

<?

function redirect($url)
{
     header('location: ' . $url);
?>
<meta http-equiv="Refresh" content="0; url=<?=$url?>" />
<script language=javascript>window.location = "<?=$url?>"</script>
<?
exit;
}

?>
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

try

Code: Select all

//given 
define ("HTTPS_SERVER", "https://www.somesite.com");

if($approved==true){
     $location = "location:".HTTPS_SERVER."/successful.php";
      header("{$location}");
      exit();
}
else{
     $location = "location:".HTTPS_SERVER."/fail.php";
     header("{$location}");
     exit();
}
as I remeber something weird happening when I tried doing something similar and the header go grumpy at me for not having things quoted right, so I did the above and it worked.
EDIT>> changed the tags before I got in trouble
mesutsahin
Forum Newbie
Posts: 10
Joined: Wed Feb 08, 2006 3:14 am

it didn't work.

Post by mesutsahin »

it didn't work.
mesutsahin
Forum Newbie
Posts: 10
Joined: Wed Feb 08, 2006 3:14 am

Post by mesutsahin »

Any of the ideas posted above has not solved my problem.
There is some exceptional situation here that I couldn't understand. There is no error message.
PHP is skipping header("locaciton:") line. It executes the line below (exit()). It exits and shows a white page.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Are you absolutely sure there's no errors? Have you checked the server logs?

I've run into a few situations where a header() call was genuinely being skipped. Adding a call to flush() or other things that force the headers to be output helped, that I remember.
User avatar
Maugrim_The_Reaper
DevNet Master
Posts: 2704
Joined: Tue Nov 02, 2004 5:43 am
Location: Ireland

Post by Maugrim_The_Reaper »

Wondering. Is it required to insert a space between the header name and value?

Location:http://example.com

vs

Location: http://example.com

Just seems to be the one thing sticking out here that I've never done. No clue myself, and can't test it for now.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I am also wondering based on that "HTTPS_SERVER" ($_SERVER['SERVER_NAME'] ?) whether it is:
location: /successful.php

or

location: http://www.example.com/successful.php

and should it be

location: http://www.example.com/successful.php
(#10850)
Post Reply