header(Location problem
Posted by: isak (---.bredband.comhem.se)
Date: February 04, 2010 09:52AM

Hello,

I got some problems with the header. My wamp server seems to allow anything or am I wrong in believing that the header(Location:...) should fail if you've done any kind of output before the header? My scripts work fine on my localhost, wamp, but not when I upload to the host. Some test on the localhost reveals that it allows pretty much anything. Are there any settings I should do, undo?

Ex:

<?php

if($x = 1) {
header('Location: pagex.php');
}
else {
header('Location: pagey.php');
}

?>

should work fine BUT

<?php

echo "this is a row on my page";

if($x = 1) {
header('Location: pagex.php');
}
else {
header('Location: pagey.php');
}

?>

should fail


Looking forward to any and all help and answers.
Br,
Magnus

Options: ReplyQuote
Re: header(Location problem
Posted by: stevenmartin99 (---.b-ras2.blp.dublin.eircom.net)
Date: February 04, 2010 10:00AM

tricky situation. no both shud work.. becasue php doesnt output until the page is completely parsed so nothing has been sent to the broswer until the page is parsed..

for a failed example use

Whitespace before the opening php tag
---------------------------------------

<?php
if($x = 1) {
header('Location: pagex.php');
}
else {
header('Location: pagey.php');
}
?>
----------------------------------------

or

Some html code before php
---------------------------------------
<html>
some html code first
<?php
if($x = 1) {
header('Location: pagex.php');
}
else {
header('Location: pagey.php');
}
?>
----------------------------------------


these will both fail on both systems.
the problem your seeing with it working on localhost but not on host is most likely due to a php setting called

outputbuffering

this determines when to send data to the browser. and how often and how much.

You will need to find out how output buffering is set on your host and then

left click wamp icon> php> php.ini and set it as theirs is..

One thing u cud do is to left click wamp icon>php>setting> outputbuffering


See if this makes it act the same as your host.. but really you shold check all their settings for it , not just is it on or off

Steven Martin
stevenmartin99@gmail.com
stevenmartin99@hotmail.com
PampServer.com - [pampserver.com]



Edited 1 time(s). Last edit at 02/04/2010 10:03AM by stevenmartin99.

Options: ReplyQuote
Re: header(Location problem
Posted by: isak (---.bredband.comhem.se)
Date: February 04, 2010 10:31AM

Thank you, you're a hero.

Kind of annoying. I had a space before the <?php tag in one of my pages. Especially when I know there must be NOTHING before the header.

I tried to fix the php setting according to your instructions but icon->php->setting has some funky thing going on. It only shows a small blue box. So, I looked in the php.ini and set

output_buffering = 4096

when I do that it tells me that my first php line is invalid, mysql_connect().

Well, well, if you have any ideas on this I would be happy but the main problem is solved. Again, thank you.

Options: ReplyQuote


Sorry, only registered users may post in this forum.