Page 1 of 1
header() function
Posted: Tue Feb 21, 2006 10:47 am
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!
JJRumi.
Posted: Tue Feb 21, 2006 10:51 am
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!"
Posted: Tue Feb 21, 2006 11:05 am
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.
Posted: Tue Feb 21, 2006 11:09 am
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!';
?>
Posted: Tue Feb 21, 2006 11:28 am
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.
Posted: Tue Feb 21, 2006 11:33 am
by feyd
You can't change that. PHP and Apache controls that output.
Posted: Tue Feb 21, 2006 11:46 am
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.
Posted: Tue Feb 21, 2006 2:45 pm
by s.dot
voodoo
