473,769 Members | 6,926 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

headers sent issue

Hi,
I've a stupid question but...

The code is the following:

if(($role!='tut or')&&(array_ke y_exists('tutor _id',$_GET)))
{
$possible_ids = array(2,6,7,8,9 ,10);
$t_id = $_GET['tutor_id'];

if(in_array($t_ id, $possible_ids)) {

$query="SELECT id_class FROM class WHERE
id_user='".$_GE T['tutor_id']."'";

$id_class=$db->get_field($que ry,id_class);

include("print_ data.php");

$formButtonLabe l = "Modifica";

}

--->else

{

//$my_echo = "hello";
//echo $my_echo;

//header('Locatio n: http://www.google.com' );
//exit();
}

}


What happens:

if in the array there's what you have in $_GET, anything works.

It's the else block that matters: :-)
- if I ONLY print $my_echo, no problems;
- if I comment $my_echo and I leave the header() uncommented, this
command doesn't work (that is, the page does not redirect);

What is happening?
How can I solve this?

I tried (in the else block) the headers_sent function too:

if (headers_sent() ) {
$my_echo = "sent";
echo $mioeco;
}

and it seems headers are sent, but maybe before I try to redirect.
Is there a way to "clean" the headers already sent??

Thanks very much,
Platero

Aug 11 '06 #1
22 2229
Rik
Platero wrote:
I tried (in the else block) the headers_sent function too:

if (headers_sent() ) {
$my_echo = "sent";
echo $mioeco;
}

and it seems headers are sent, but maybe before I try to redirect.
Is there a way to "clean" the headers already sent??
No, once the headers are sent you're stuck with it. Remember: even a space
before <?php will result in headers being sent.

Headers must be sent before any output, whatever it is, wether it's
generated from php or fram a static file.

Grtz,
--
Rik Wasmus
Aug 11 '06 #2

Platero wrote:
Hi,
I've a stupid question but...

The code is the following:

if(($role!='tut or')&&(array_ke y_exists('tutor _id',$_GET)))
{
$possible_ids = array(2,6,7,8,9 ,10);
$t_id = $_GET['tutor_id'];

if(in_array($t_ id, $possible_ids)) {

$query="SELECT id_class FROM class WHERE
id_user='".$_GE T['tutor_id']."'";

$id_class=$db->get_field($que ry,id_class);

include("print_ data.php");

$formButtonLabe l = "Modifica";

}

--->else

{

//$my_echo = "hello";
//echo $my_echo;

//header('Locatio n: http://www.google.com' );
//exit();
}

}


What happens:

if in the array there's what you have in $_GET, anything works.

It's the else block that matters: :-)
- if I ONLY print $my_echo, no problems;
- if I comment $my_echo and I leave the header() uncommented, this
command doesn't work (that is, the page does not redirect);

What is happening?
How can I solve this?

I tried (in the else block) the headers_sent function too:

if (headers_sent() ) {
$my_echo = "sent";
echo $mioeco;
}

and it seems headers are sent, but maybe before I try to redirect.
Is there a way to "clean" the headers already sent??

Thanks very much,
Platero
Use output buffering, should fix your problem.

Aug 12 '06 #3
dawnerd wrote:
Platero wrote:
>>Hi,
I've a stupid question but...

The code is the following:

if(($role!='t utor')&&(array_ key_exists('tut or_id',$_GET)))
{
$possible_ids = array(2,6,7,8,9 ,10);
$t_id = $_GET['tutor_id'];

if(in_array($t_ id, $possible_ids)) {

$query="SELECT id_class FROM class WHERE
id_user='".$_ GET['tutor_id']."'";

$id_class=$db->get_field($que ry,id_class);

include("print_ data.php");

$formButtonLabe l = "Modifica";

}

--->else

{

//$my_echo = "hello";
//echo $my_echo;

//header('Locatio n: http://www.google.com' );
//exit();
}

}


What happens:

if in the array there's what you have in $_GET, anything works.

It's the else block that matters: :-)
- if I ONLY print $my_echo, no problems;
- if I comment $my_echo and I leave the header() uncommented, this
command doesn't work (that is, the page does not redirect);

What is happening?
How can I solve this?

I tried (in the else block) the headers_sent function too:

if (headers_sent() ) {
$my_echo = "sent";
echo $mioeco;
}

and it seems headers are sent, but maybe before I try to redirect.
Is there a way to "clean" the headers already sent??

Thanks very much,
Platero


Use output buffering, should fix your problem.
Better to find and fix the problem than unnecessarily add overhead by
buffering the output.

Output buffering has its uses. But to use it to get around a problem in
the code is not a good idea, IMHO.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Aug 12 '06 #4

Jerry Stuckle wrote:
dawnerd wrote:
Platero wrote:
>Hi,
I've a stupid question but...

The code is the following:

if(($role!='tu tor')&&(array_k ey_exists('tuto r_id',$_GET)))
{
$possible_ids = array(2,6,7,8,9 ,10);
$t_id = $_GET['tutor_id'];

if(in_array($t_ id, $possible_ids)) {

$query="SELECT id_class FROM class WHERE
id_user='".$_G ET['tutor_id']."'";

$id_class=$db->get_field($que ry,id_class);

include("print_ data.php");

$formButtonLabe l = "Modifica";

}

--->else

{

//$my_echo = "hello";
//echo $my_echo;

//header('Locatio n: http://www.google.com' );
//exit();
}

}


What happens:

if in the array there's what you have in $_GET, anything works.

It's the else block that matters: :-)
- if I ONLY print $my_echo, no problems;
- if I comment $my_echo and I leave the header() uncommented, this
command doesn't work (that is, the page does not redirect);

What is happening?
How can I solve this?

I tried (in the else block) the headers_sent function too:

if (headers_sent() ) {
$my_echo = "sent";
echo $mioeco;
}

and it seems headers are sent, but maybe before I try to redirect.
Is there a way to "clean" the headers already sent??

Thanks very much,
Platero

Use output buffering, should fix your problem.

Better to find and fix the problem than unnecessarily add overhead by
buffering the output.

Output buffering has its uses. But to use it to get around a problem in
the code is not a good idea, IMHO.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
I couldn't agree with you more. I find it always better to do all of
the dirty work before anything is outputted. IMO it's bad practice to
use PHP in the middle of html, unless it's used to output text.

Instead of say checking variables for errors and redirecting to a new
page in the middle of a page, do it before any html will even be
outputted, that way you are safe to set headers and the work.

Aug 12 '06 #5

Thanks very much.
I red all the thread and I solved :-)

Platero
Aug 12 '06 #6
On Fri, 11 Aug 2006 23:26:44 -0400, Jerry Stuckle wrote:
Output buffering has its uses. But to use it to get around a problem in
the code is not a good idea, IMHO.
The whole business with headers is unnecessarily restrictive and real pain
in the neck or lower. Newer versions of Apache are more and more tolerant,
as they should be. If ob_start will solve my problem, I'll use it in a
heartbeat. It is a solution in 99% of the cases. For the remaining 1%,
it's still a pain.

--
http://www.mgogala.com

Aug 12 '06 #7
Mladen Gogala wrote:
On Fri, 11 Aug 2006 23:26:44 -0400, Jerry Stuckle wrote:

>>Output buffering has its uses. But to use it to get around a problem in
the code is not a good idea, IMHO.


The whole business with headers is unnecessarily restrictive and real pain
in the neck or lower. Newer versions of Apache are more and more tolerant,
as they should be. If ob_start will solve my problem, I'll use it in a
heartbeat. It is a solution in 99% of the cases. For the remaining 1%,
it's still a pain.
This not not an Apache restriction. It's one of the HTTP protocol, and
there isn't anything Apache can do to "fix" it.

And I understand. You're rather go for a "quick fix" than find and fix
the real problem.

Glad you're not on my team.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Aug 12 '06 #8
On Sat, 12 Aug 2006 09:34:36 -0400, Jerry Stuckle wrote:
This not not an Apache restriction. It's one of the HTTP protocol, and
there isn't anything Apache can do to "fix" it.
I don't know, but I do see less problems with Apache 2.0.54 then with
Apache 1.0.3x. I haven't quantified anything
And I understand. You're rather go for a "quick fix" than find and fix
the real problem.
That does fix the real problem: unnecessary painful issue with "headers
already sent". If all that I want to do is to issue header() function and
redirect browser onto another page, then I don't really care about the
"real problem".
>
Glad you're not on my team.
No need to get personal here, but since you've put it that way, I too am
glad that I am not on your team.
--
http://www.mgogala.com

Aug 12 '06 #9
Mladen Gogala wrote:
On Sat, 12 Aug 2006 09:34:36 -0400, Jerry Stuckle wrote:

>>This not not an Apache restriction. It's one of the HTTP protocol, and
there isn't anything Apache can do to "fix" it.

I don't know, but I do see less problems with Apache 2.0.54 then with
Apache 1.0.3x. I haven't quantified anything

>>And I understand. You're rather go for a "quick fix" than find and fix
the real problem.


That does fix the real problem: unnecessary painful issue with "headers
already sent". If all that I want to do is to issue header() function and
redirect browser onto another page, then I don't really care about the
"real problem".
Nope. The real problem is why you're sending data in the first place.
There may be a valid reason. However, just using ob_start() just hides
the real problem.
>
>>Glad you're not on my team.


No need to get personal here, but since you've put it that way, I too am
glad that I am not on your team.

Yep, you wouldn't get away with that on my team. Like anything else -
you should have a reason for using ob_start(). And just using it to
hide the fact you've sent out something ahead of time - but have no idea
what you've sent - is not a valid reason.

Another case of a quick fix instead of finding the real problem. Sooner
or later it will come back to bite you.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Aug 13 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2601
by: Dariusz | last post by:
I have a problem where when I run the PHP code offline, there are no errors produced and the code runs as expected. However when I uploaded the same script and run it, it says the headers have already been sent. The script is for a "downloader" type script, where the user clicks on a file link (to the PHP script) using $_GET to pass the selected files ID to the script, and the information about the file is read out from a database, also...
1
2450
by: None | last post by:
Hello, I am a total newbie to PHP and programming in general. I am playing around with a PHP / MySQL shopping cart script which I found at http://www.macromedia.com/devnet/mx/dreamweaver/articles/php_cart.html. When I try to start a session or create a cookie, I get the following errors. Warning: Cannot send session cache limiter - headers already sent (output started at /wrapper_head2.php:27) in /cart.php on line 13 Warning: Cannot...
5
2543
by: Philip Ronan | last post by:
OK, here's my 2p worth: === Q. Why am I getting the error message 'Headers already sent'? A. PHP produces this error message when you try to set a header for a web page after you have already started sending out the content of the page. Web content is always delivered with a few headers at the top, ending with a blank line. For example, a web page might start like this:
10
3045
by: Lisa Pearlson | last post by:
Hi, I have a php script with no more than this: <?php echo "Hello World!"; ?> When a webbrowser client requests data, it receives Apache server headers, followed by my data: HTTP/1.1 200 OK
8
24278
by: Andreas Klemt | last post by:
Hello, I get this error Message "cannot redirect after http headers have been sent" when I do this response.redirect ("home.aspx") How can I find out with vb.net if already a http header has been sent like If response.IsSentHttpHeader then ....
5
11528
by: gibble | last post by:
Hi, I am going crazy. We get a hundred or so of these errors each day and while the fix would seem obvious, the error does not include a line number! -------------------- Process information: Process ID: 10084 Process name: w3wp.exe
2
2262
by: WALDO | last post by:
I am having the exact same problem. I am using VS2008 (.Net 3.5) and I can't set the Expires date out any further than one day. Doing a little reflection, I see that in the HttpCachePolicy class, SetExpires() method, if the expires is already set, it will only change if the new expiration date is less than the existing one. I have removed all of my custom HttpModules and discovered that none of mine are setting the expiration.
3
2207
by: Webrickco | last post by:
Hi, I have the following issue when i upload my files to my hosting. I cannot send the following headers: <?php header('Content-Type: text/xml'); header('Pragma: no-cache'); When I execute the code, I get:
6
11497
Markus
by: Markus | last post by:
Things to discuss: Headers What are they? What does PHP have to do with headers? Why can they only be sent before any output? Common causes
0
9589
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
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
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...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5309
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
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3565
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.