PHP
--
Questions
--
Followers
Top Experts
I have a few scripts whereby once a form is submitted (and info uploaded and stored in the db), it redirects to another page.
The problem is, that once I uploaded it to my clients server, I get this error;
Warning: Cannot modify header information - headers already sent by (output started at /path/to/mainframe_distrib
Now, I know that header() must be before any output, but the site is in frames and I need the code where it is, it also worked fine on my Linux server.
I trie ob_start() - but that caused more errors than it fixed....
Anyway, heres my code;
**************************
$insertGoTo = "mainframe_distributors_th
if (isset($_SERVER['QUERY_STR
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
**************************
Thanks for any help.
Christian
Zero AI Policy
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
First thing I registered was that you are enclosing the HEADER statement with the } and it's nowhere opened. Well, maybe there's just a cut of your code, so in that way it's ok.
Second, why you are using sprintf in a HEADER statement? That's something I've never seen before. I think this may cause the problem, because sprintf output the text to a browser and therefore it must send header the information before it can print anything out.
Why don't you simply use: header("Location: ".$insertGoTo); ?
regards
CyberGhost
why not use javascript instead to redirect?
....
<script language="JavaScript">
window.location = <?=$insertGoTo?>
</script>
.....
I changed it to that and got a parse error, so i changed it around a bit a few times with the same parse error...
$insertGoTo = "mainframe_distributors_th
<script language="JavaScript">
window.location = $insertGoTo;
</script>
Cyberghost, yeah that was just a snippet of my code, i tried
$insertGoTo = "mainframe_distributors_th
if (isset($_SERVER['QUERY_STR
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header("Location: %s", $insertGoTo);
}
And got the header error again.
Thanks guys!
Christian






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Do NOT use the comma, but a dot after the " ...
Code:
header("Location: ".$insertGoTo);
NOT
header("Location: ", $insertGoTo);
... dot is an operator that combines string literals and variables. Don't put there that %s, otherwise it won't work.
BTW: it's not a good idea to use JavaScript when using PHP to relocate, because there could be a guy with JavaScript turned off and then nothing happen. PHP will allways work, just learn how to use it ;o)
BTW2: you may put the exit; command to exit execution of further code lines when relocating via header();
So your code finally should looks like:
$insertGoTo = "mainframe_distributors_th
if (isset($_SERVER['QUERY_STR
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header("Location: ".$insertGoTo);
exit;
}
regards
CyberGhost
Still getting an error with that code;
$insertGoTo = "mainframe_distributors_th
if (isset($_SERVER['QUERY_STR
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header("Location: ".$insertGoTo); // -> Line 81 is the error.
exit;
}
Thanks!
And jkna, I will use that if I cant get this to work tonight, but as Cyber said, if somebody has it turned off etc.. :) Thanks again!
Christian

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
you can use the meta refresh tag instead.
example :
<META HTTP-EQUIV="refresh" content="1;URL=http://www.yoursite.com/newpage.htm">
just replace the url site with your variable
But got a suggestion: are you sure, that there isn't any code before the 81st line that make some output (like you had in that HEADER part)?
Sometimes this error also occurs if you have some blank lines even before the <? and ?> tags.
I mean, don't you have something like:
*** File starts here ***
<-- blank line (there ain't be even a single character, only an empty line)
<? <-- followed by first PHP tag
...
*** File ends here ***
OR - don't you have even the <HTML> or <HEAD> or <TITLE> or ANY of the HTML tags before the <? php tag?
BTW: it seems there is all ok in your coding if you only get the header error (mean no condition errors or so befor the HEADER part)
regards
CyberGhost
Also, you should check for any whitespace before/between any of the <? tags - I've been frustrated by that error before just to find I've put a space before the first opening <? tag.
Next option to try is to put an exit() command on line 78 - this will stop the code from going any further, so you can view the source and see what has been output.






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Sorry boys, but I'll stick with the java atm.
Thanks everyone for their help!
Christian
--Below is the error that comes up in IE 6.0 & Netscape
Start_____________________
Warning: Cannot modify header information - headers already sent by (output started at /home/content/f/u/n/functi
__________________________
there is code where line 45 is and where the error is generating from?
--Below is the code:
start_____________________
$MM_restrictGoTo = "login.php";
if (!((isset($_SESSION['MM_Us
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0)
$MM_referrer .= "?" . $QUERY_STRING;
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo); __________________________
exit;
__________________________
Please let me know if you have any ideas??
thanks a bunch!
onlycubes

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
__________________________
<?php
# FileName="Connection_php_m
# Type="MYSQL"
# HTTP="true"
$hostname_connBlueSky = "mysql31.secureserver.net"
$database_connBlueSky = "BlueSkyData215";
$username_connBlueSky = "BlueSkyData215";
$password_connBlueSky = "belle5";
$connBlueSky = mysql_pconnect($hostname_c
?>
---------------------end






EARN REWARDS FOR ASKING, ANSWERING, AND MORE.
Earn free swag for participating on the platform.
Please open php.ini file
Find
output_buffering
And set
output_buffering = On = On
Replace
output_buffering = On
Please send point to me!
header can be used to specify a redirection or a type of the file to be returned with php..
ok.. now for your problem..
1. you included a script with header("location:xxxxx") in the middle of html.. for examle
<div><?php include "filewithheader.php";?> this is not allowed.. you should put that file on top of everything that will output html
2. you write a header function after some html.
to solve it you need to put the header function or any included file with that header function on top of everything, ofcourse after some connection file if you use databases inside that script..

Get a FREE t-shirt when you ask your first question.
We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.
PHP
--
Questions
--
Followers
Top Experts
PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.