Page 1 of 1

Reading html content in a POST request

Posted: Mon May 29, 2006 8:16 am
by jjrumi
Hi there!
I've found myself in trouble trying to read the following HTTP request:

---------------------------------------------------------
POST /testing.php HTTP/1.1
Host: localhost
Content-Type: text/html
Content-length: 60

<html>
<body>
MAXUSERS=21
</body>
</html>

--------------------------------------------------------

What I wanna read is the "MAXUSERS=21" text... But I don't know how to read it, or the whole content of the request.

Can anyone help? :)

JuanLu.

Posted: Mon May 29, 2006 10:23 am
by Ambush Commander
You could use regular expressions...

Code: Select all

$matches = array();
preg_match('/MAXUSERS=(\d+)/', $html, $matches);
echo $matches[1]; // returns 21

not how to extract info from it, but how to READ it!

Posted: Mon May 29, 2006 1:00 pm
by jjrumi
yep!!!

I think I didn't explain it correctly. I don't know how to read it.

When I get the request from an external server, in THIS way... how do I read it? How do I read from <html> to </html>

It's not in the $_POST array, nor in the $_SERVER, $_GET.... .... ...

thanks !!!

Posted: Mon May 29, 2006 1:02 pm
by Ambush Commander
You'd have to open a connection to the server and retrieve it. file_get_contents(), in more recent versions of PHP, should work (just supply a URL instead of filepath), but you can also use CURL.

Posted: Mon May 29, 2006 4:40 pm
by ianhull
<php $_GET['maxusers']; ?>

or <?php $_POST['maxusers'];?>

or <?php REQUEST['maxusers'];?>

Posted: Mon May 29, 2006 6:23 pm
by Ambush Commander
I don't understand. Are you posting a text area to testing.php?

I'll try to explain again :)

Posted: Tue May 30, 2006 12:31 am
by jjrumi
Hi again!!!

to ianhull -->
Please, read my posts... I'm not receiving a common POST Request. As you may know, a common one would be:

Code: Select all

POST /test.php HTTP/1.1
Host: localhost
Content-Length: 27
Content-Type: application/x-www-form-urlencoded

userid=joe&password=guessme
--------------------------------------------------------------------------

to Ambush Commander-->
Your post is interesting, but it's interesting if you want to get information from a server. As you said "You'd have to open a connection to the server and retrieve it.". But it's not the case. I'm not sending the request, I'm receiving it.

The problem is that the external server is passing me information in that singular way. It's not passing me info in a common GET way o POST way, it's just sending a POST without variables and it's adding a text/html content which could be "MAXUSER=21" or "My life is boring" or an XML utf encoded between the body tags.

I want to read THAT text/html he's sending me within the request. :wink:

Posted: Tue May 30, 2006 8:22 am
by Ambush Commander
Oh! I assume you're talking about RAW post data, you do that by fopen('php://input');

But you probably should investigate other technologies that do this already, ilke XMLRPC or SOAP.

:D

Posted: Tue May 30, 2006 9:07 am
by jjrumi
Ambush Commander --> You are my man!

Thanks, dude, file_get_contents('php://input'); goes wonderful as well.

:D