473,246 Members | 1,584 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,246 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 39148
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: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...

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.