[PHP] POSTing to another site

I’m writing a blog, and I want to make sure that all my pages validate as XHTML. I want to let people post comments, but they might not post validating HTML.

So I thought I’d use the W3’s XHTML validator(saves me a lot of work)

The problem with this is that the W3’s XHTML validator accepts data via POST only, and not GET:trout:.

Does anyone know how I can send info to another page on a whole different server using POST, and then read the data sent back?

I know how to use fopen() to manipulate data for GET pages, it’s just POST that is the problem.

Thanks :slight_smile:

this works for the validator:

http://validator.w3.org/check?uri=http%3A%2F%2Fwww.reqkills.com&charset=(detect+automatically)&doctype=(detect+automatically)&ss=1

and that is get…

http://validator.w3.org/

that’s not the validator I meant… but actually, I might have come up with an alternative anyway…

I meant the WDG validator here: http://www.htmlhelp.com/tools/validator/direct.html

I suppose I could write a little snippet of code that would write the HTML to a unique file and then send that URL to the W3C validator.

I’d still be interested in knowing whether there is a way of doing this though.

I don’t think there is a way of sending post variables to another site like that for security reasons… :sigh:

Aha! the cURL library looks like just what the doctor ordered.

http://uk2.php.net/manual/en/ref.curl.php

Now all I gotta do is figure out how to do it :stuck_out_tongue:

Well, I got it working.

In case anyone wants to know how, I used cURL from the command line. My host must have got it installed or something(they didn’t have the library).

Here’s the code I used:


<?php 
$html = urlencode(
'
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>test</title></head>
<body><p>This is a test of the XHTML validator</p></body>
</html>
');
$var = shell_exec("curl -d \"area=$html&charset=UTF-8&warnings=yes&input=yes\" http://www.htmlhelp.com/cgi-bin/validate.cgi");
print $var;
?>

with the output: www.skehin.com/php_curl.php