header() function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jjrumi
Forum Newbie
Posts: 14
Joined: Tue Feb 21, 2006 10:37 am

header() function

Post by jjrumi »

Hi everybody!

I've got some trouble trying to send customized http headers (response http headers to be more specific).

What I'm trying to send using:
header("HTTP 200 OK
Content-Type: text/plain

Thanks por submit!");

is:
HTTP 200 OK
Content-Type: text/plain

Thanks for submit!


But what I'm getting is:
HTTP 200 OK
Content-Type: text/plain

Thanks por submit!
Date: Bla bla bla
X-Powered-By: PHP 5.05 bla bla bla
Server: Apache bla bla bla
Connection:closed
bla bla bla bla


Is it possible with the header() function??? or am I trying to fish in an empty hole? Does anybody knows how to do it?

Thank you all! :o

JJRumi.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You shouldn't try to send page level output through header(). PHP has to add more data into the headers.
Your header call should only be Content-type: text/plain
You should then echo "Thannks for submit!"
jjrumi
Forum Newbie
Posts: 14
Joined: Tue Feb 21, 2006 10:37 am

Post by jjrumi »

Ok,
That's it feyd, I'm NOT trying to send page level output. I'm trying to send HTTP Header level output.
For example, if I have a GET request to http://www.mywebsite.com like
GET page/cars/form.php?var1=value1&var2=value2 HTTP/1.1
Host:www.mywebsite.com

I want to answer:

Thank you for Submit

or

HTTP 200 OK
Thank you for Submit

or

HTTP 200 OK
Content-Type:text/plain

Thank you for Submit


I'm not sure if I'm clear enough. I want to answer whatever I want in a HTTP Header level output.

JJRumi.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

"Thank you for Submit" is a page level output.

PHP automatically sends a 200 response code back if you don't alter it.

Code: Select all

<?php

header('Content-type: text/plain');
echo 'Thank you for Submit!';

?>
jjrumi
Forum Newbie
Posts: 14
Joined: Tue Feb 21, 2006 10:37 am

Post by jjrumi »

Thank you again, feyd.
Let me show you it this way:
If you create a file "pp.php" filled with:
<?php
header('Content-type: text/plain');
echo "Thank you for Submit!";
?>

and you place it in your Server DocumentRoot, so you can reach it with your browser using "localhost/pp.php".

OK.

Now, if you use "Start --> Execute" and type: "telnet localhost 80"
Once you're in, type:
GET /pp.php HTTP/1.1
host: localhost


You'll get something like that:


HTTP/1.1 200 OK
Date: Tue, 21 Feb 2006 17:21:45 GMT
Server: Apache
X-Powered-By: PHP/5.0.5
Content-Length: 22
Content-Type: text/plain

Thank you for Submit!


OK.... I don't want those lines... I just want reply "Thank you" or "Jajajaajja" or whatever.
I've seen it in some servers, but how to do it????

JJRumi.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You can't change that. PHP and Apache controls that output.
jjrumi
Forum Newbie
Posts: 14
Joined: Tue Feb 21, 2006 10:37 am

Post by jjrumi »

:)
In an unconscious way you have shown me a way to put

Context-Type:text/plain

bla bla bla

at the bottom of the header AND I CAN USE THIS. :)
I haven't tried to use only

Code: Select all

header("Content-Type: text/plain");
echo "bla bla bla";
Anyway!!!
I'm quite curious about my first question. If anybody knows I'll thank him.

JJRumi.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

voodoo :lol:
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply