Reading html content in a POST request

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

Reading html content in a POST request

Post 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.
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

You could use regular expressions...

Code: Select all

$matches = array();
preg_match('/MAXUSERS=(\d+)/', $html, $matches);
echo $matches[1]; // returns 21
jjrumi
Forum Newbie
Posts: 14
Joined: Tue Feb 21, 2006 10:37 am

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

Post 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 !!!
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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.
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

Post by ianhull »

<php $_GET['maxusers']; ?>

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

or <?php REQUEST['maxusers'];?>
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

I don't understand. Are you posting a text area to testing.php?
jjrumi
Forum Newbie
Posts: 14
Joined: Tue Feb 21, 2006 10:37 am

I'll try to explain again :)

Post 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:
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post 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.
jjrumi
Forum Newbie
Posts: 14
Joined: Tue Feb 21, 2006 10:37 am

:D

Post by jjrumi »

Ambush Commander --> You are my man!

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

:D
Post Reply