944,123 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 7914
  • PHP RSS
Nov 29th, 2006
0

header() not redirecting for some reason...

Expand Post »
i'm writing a redirect.php page for a CMS. the admin user makes whatever changes they want to certain information in the database, then clicks submit. they are taken to redirect.php which handles all the sql commands depending on what the admin wanted to change. and then they are redirected to another page, depending on the types of changes they made, as well... the header is not working. here's the error:

Warning: Cannot modify header information - headers already sent by (output started at /../../../admin/redirect.php) in /../../../admin/redirect.php on line 41

[php]
<?php
$uID = $_POST['editID'];
$sub_opt = $_POST['sub_opt'];
$brideFname = $_POST['brideFname'];
$brideLname = $_POST['brideLname'];
$groomFname = $_POST['groomFname'];
$groomLname = $_POST['groomLname'];
$ship_add = $_POST['ship_add'];
$ship_city = $_POST['ship_city'];
$ship_state = $_POST['ship_state'];
$ship_zip = $_POST['ship_zip'];
$_POST['event_month'];
$_POST['event_day'];
$_POST['event_year'];

if($_POST['event_month2'] != NULL){
$event_month = $_POST['event_month2'];
}if($_POST['event_day2'] != NULL){
$event_day = $_POST['event_day2'];
}if($_POST['event_year2'] != NULL){
$event_year = $_POST['event_year2'];
}

if($sub_opt == "cancel"){
echo "<CENTER>All changes were cancelled. You are being redirected to Home.</CENTER>";
$redirect = "admin1.php?action=view_all";
}elseif($sub_opt == "save"){
//open connection
//SQL commands
//close connection
echo "<CENTER>Your changes have been saved. You are being redirected to Home.";
$redirect = "admin1.php?action=view_all";
}elseif($sub_opt == "save_reg"){
//open connection
//same SQL commands
//close connection
echo "Your changes have been saved. You are being redirected to Registry.";
$redirect = "updateRegistry.php";
}

header("Location: $redirect");
?>
[/php]
Last edited by boo_lolly; Nov 29th, 2006 at 4:39 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Light Poster
boo_lolly is offline Offline
35 posts
since Nov 2006
Nov 30th, 2006
0

Re: header() not redirecting for some reason...

if you are going to use a header tag YOU CANNOT output any text/html to the user, which means you need to get rid of all the echo.

when you see this error: Warning: Cannot modify header information - headers already sent by

it means that you've already send data to the user.
comment all the lines that contain echo and you will see your code should work just fine
Last edited by paradox814; Nov 30th, 2006 at 8:35 pm.
Reputation Points: 13
Solved Threads: 4
Posting Whiz
paradox814 is offline Offline
351 posts
since Oct 2004
Nov 30th, 2006
0

Re: header() not redirecting for some reason...

what you could do to fix the problem is put this in the meta tag of the html:
[html]<meta http-equiv="Refresh" content="4;url=http://www.domain.com/link.html">[/html]

you would need to replace the url with $redirect and the 4 seconds with however long you see fit

and it will redirect the user to the new page after 4 seconds
Reputation Points: 13
Solved Threads: 4
Posting Whiz
paradox814 is offline Offline
351 posts
since Oct 2004
Dec 1st, 2006
0

Re: header() not redirecting for some reason...

Warning: Cannot modify header information - headers already sent by (output started at /../../../admin/redirect.php) in /../../../admin/redirect.php on line 41

If you are facing this Warning....it means you have some ECHO syntaxes or you may have some waste spaces that are not allowed while using "header" function....Make sure tht u ve removed all ECHOs and waste spaces above the Header.... your function will work fine...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
silverline0529 is offline Offline
2 posts
since Dec 2006
Dec 1st, 2006
0

Re: header() not redirecting for some reason...

mmm, the delimiter between a HTTP header and the HTTP response is two line returns (one empty line). you can put aload of stuff before a header, but not an empty line... lol.. PHP tries to handle this automatically (in true CGI you have to send a content-type/location/[some other headers work], otherwise the request fails, if you use echo before you set a header, PHP sends a text/html content-type.)

So, as said, put header() before you do anything that could produce output.

The Location header is a request-level redirect (meaning a page that sends the Location header is never shown); so if you actually want to show something on the page during the redirect, maybe the Redirect header is more appropriate.
Moderator
Featured Poster
Reputation Points: 522
Solved Threads: 64
Veteran Poster
MattEvans is offline Offline
1,091 posts
since Jul 2006
May 7th, 2008
0

Re: header() not redirecting for some reason...

don't use echo in your code
Reputation Points: 10
Solved Threads: 0
Light Poster
almualim is offline Offline
28 posts
since May 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: can anybody send eclipse for php
Next Thread in PHP Forum Timeline: Please help with my first upload script..





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC