473,406 Members | 2,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

header (Location: ) not working on web server

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
8 39185
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
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
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
..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
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
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
..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
Thanks Jonathan, that solved the problem .... :-)

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

Feb 8 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: jock | last post by:
A script i'm working on is behaving real strange. It is more or less the same as dozens of others that work aok. Info is posted from one script to another, the second script does some work...
6
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:...
10
by: Margaret MacDonald | last post by:
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...
23
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...
2
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'...
6
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))...
4
by: geshan | last post by:
In php5 I am not able to use include funciton and header("location:""" together please help.
4
by: henryrhenryr | last post by:
I'm using Win2k with Apache 2, PHP 5.2 for my local test server. My problem is that I think the header('Location ...') function isn't sending the header immediately and the rest of my script is...
6
johny10151981
by: johny10151981 | last post by:
Its not a php Question. Its a HTTP question how web server send client Location header request. The thing is, after sending "\r\n\r\n" web server start to send data to web client but even...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
agi2029
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,...

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.