473,698 Members | 2,943 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

header (Location: ) not working on web server

I have a simple php page in which I use

header("Locatio n: 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 39272
php newbie wrote:
I have a simple php page in which I use

header("Locatio n: 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_bufferi ng = 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.p hp" >

// 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><hea d></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.p hp" >

// 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_condi tion == TRUE ){
//put redirect here
header("Locatio n: 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
2415
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 (nothing too taxing, just checks the input and updates/moves a couple of files) then redirects to the first script. Its one of these second scripts I'm having trouble with. As I was writing it, instead if redirecting to the initial script I would...
6
18275
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: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting
10
5655
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 header('Location: ...) jump to page A on success or falls through to the jump to page B. This is the code: if ( mysql_query( 'LOCK TABLES tableX WRITE', $link ) ) { mysql_query( $q, $link ) ; // store the record
23
3637
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 page I don't get any session variable values! BTW, I used a relative location in the Location header, not an absolute URL. The behavior looks like it started another session, but it should not have. Ideas? TIA,
2
8919
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' ); I'd like to use particular read out data from my database (URL) (variable $result).
6
5453
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)) && ($name='valid')){ // insert some data into MySQL.
4
10418
by: geshan | last post by:
In php5 I am not able to use include funciton and header("location:""" together please help.
4
3121
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 running before the page redirects. I am using a $_SESSION array to transfer messages from one page to the next. I want the message available only once, then it should be deleted. I had been using the technique something like this: if...
6
2288
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 though in that situation if we create a Location header request it works look at the below example. <?php echo "johny"; header("Location: request.php"); ?>
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9031
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8902
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7740
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.