| | |
header() not redirecting for some reason...
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Nov 2006
Posts: 35
Reputation:
Solved Threads: 1
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]
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.
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
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.
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
[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
•
•
Join Date: Dec 2006
Posts: 2
Reputation:
Solved Threads: 0
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...
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...
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.
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.
Plato forgot the nullahedron..
![]() |
Similar Threads
- Warning: Cannot modify header information (PHP)
- Global Header, Footer and Side Bars (Site Layout and Usability)
- Global Header, Footer and Side Bars (HTML and CSS)
- Page redirecting for no reason (HTML and CSS)
- Classes and header files (C)
- Request Header Parsing in Javascript (JavaScript / DHTML / AJAX)
Other Threads in the PHP Forum
- Previous Thread: can anybody send eclipse for php
- Next Thread: Please help with my first upload script..
Views: 4287 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl customizableitems database date directory display download dynamic echo email error file files folder form format forms forum function functions google headmethod href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail malfunctioning menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube






