By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,506 Members | 1,876 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,506 IT Pros & Developers. It's quick & easy.

header (Location: ) not working on web server

P: n/a
I have a simple php page in which I use

header("Location: http://www.example.com/");

to redirect the user to another php page. The php script works on my
local machine but when I upload it to the web server for hosting the
redirection does not work. Instead on one server it gives the standard
header error

Warning: Cannot modify header information - headers already sent
by .......

while on the other server, I dont see this error but it also does not
redirect just refreshes the page when I click the Submit button.

Does anybody know how can i resolve this?
Thanks

Feb 7 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
php newbie wrote:
I have a simple php page in which I use

header("Location: http://www.example.com/");

to redirect the user to another php page. The php script works on my
local machine but when I upload it to the web server for hosting the
redirection does not work. Instead on one server it gives the standard
header error

Warning: Cannot modify header information - headers already sent
by .......

while on the other server, I dont see this error but it also does not
redirect just refreshes the page when I click the Submit button.

Does anybody know how can i resolve this?
Thanks
Yes,

On one server you created output before using hedaer(), and on the other
not.
You cannot use header if you send information already.

Possibly you have an error/notice/warning/whatever on 1 server (and thus
produce output) and not on the other?

Regards,
Erwin Moller
Feb 7 '07 #2

P: n/a
Hello Erwin, I did not understand your response. Its the same php
page, why is it showing the warning on one server and not on another
and why is the same page working on my local machine and not working
when I upload it to the server.
I would really appreciate your help, I am a newbie to php and not
aware of any configuration settings that I might need to change.
Thanks
Feb 7 '07 #3

P: n/a
On Feb 7, 5:35 pm, "php newbie" <arpit...@gmail.comwrote:
Hello Erwin, I did not understand your response. Its the same php
page, why is it showing the warning on one server and not on another
and why is the same page working on my local machine and not working
when I upload it to the server.
I would really appreciate your help, I am a newbie to php and not
aware of any configuration settings that I might need to change.
Thanks
Redirecting with the header functions works only if no output has been
produced before this command. If you are using the same files on both
servers it could be that the settings of those servers are different.

E.g. If your first server is configured to show no warnings (e.g. when
a variable is used without being defined before) and the second server
is configured to show those warnings, it will work on the first server
but will not on the second.

In this case a workaround would be to use the same configurations, or
to clear up your code in order to produce no warnings.

Good luck
Martin

------------------------------------------------
online accounting on bash bases
Online Einnahmen-Ausgaben-Rechnung
http://www.ea-geier.at
------------------------------------------------
m2m server software gmbh
http://www.m2m.at
Feb 7 '07 #4

P: n/a
..oO(php newbie)
>Hello Erwin, I did not understand your response. Its the same php
page, why is it showing the warning on one server and not on another
and why is the same page working on my local machine and not working
when I upload it to the server.
Check the output of phpinfo(). It looks like on your machine output
buffering is enabled by default (output_buffering = 1).
>I would really appreciate your help, I am a newbie to php and not
aware of any configuration settings that I might need to change.
You should try to fix the problem instead. Don't send any output to the
browser before the header() call. The error message shows where the
output started.

Micha
Feb 7 '07 #5

P: n/a
Thanks all for valuable inputs, I will try phpinfo() function tonight.
What could be the reason for code to be working on my local machine
and not working on the web server.

Following is the pseudo code of what my php page looks like

---- temp1.php --------
<html>
<head>
</head>
<body>
<?php

// test if this is postback
// if this is postback
// create session and write form fields to the session
// call header(Location: ) function to redirect to temp2.php page

?>

<form method="post" action="temp1.php" >

// form input fields

<input type="submit" value="Submit" >
</form>
</body>
</html>
Feb 7 '07 #6

P: n/a
php newbie wrote:
Thanks all for valuable inputs, I will try phpinfo() function tonight.
What could be the reason for code to be working on my local machine
and not working on the web server.

Following is the pseudo code of what my php page looks like

---- temp1.php --------
<html>
<head>
</head>
<body>
The "<html><head></head><bodystuff *cannot* be above your header call
that flows...
<?php

// test if this is postback
// if this is postback
// create session and write form fields to the session
// call header(Location: ) function to redirect to temp2.php page

?>

<form method="post" action="temp1.php" >

// form input fields

<input type="submit" value="Submit" >
</form>
</body>
</html>

---- temp1.php -------- Should be:

<?php
//do what ever testing you want to determine if you want to redirect
if( $redirect_condition == TRUE ){
//put redirect here
header("Location: http://www.example.com/temp2.php");
}
//if your not redirecting then put your page below
?>
<html>
<head>...

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
Feb 7 '07 #7

P: n/a
..oO(php newbie)
>Thanks all for valuable inputs, I will try phpinfo() function tonight.
What could be the reason for code to be working on my local machine
and not working on the web server.
As said: different configuration.

Micha
Feb 7 '07 #8

P: n/a
Thanks Jonathan, that solved the problem .... :-)

Thanks everybody else for their inputs.....
good night !!!!

Feb 8 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.