Thursday, December 6, 2012

making POST request from PHP

here is the example which makes POST request to recaptcha verify API from PHP code. pretty easy !

$postdata = http_build_query(
    array(
        'privatekey' => 'your private key',
        'remoteip' => '$_SERVER["REMOTE_ADDR"]',
        'challenge' => '$_POST["recaptcha_challenge"]',
        'response' => '$_POST["recaptcha_response"]'
    )
);

$options = array('http' =>
    array(
        'method'  => 'POST',
        'header'  => 'Content-type: application/x-www-form-urlencoded',
        'content' => $postdata
    )
);

$context = stream_context_create($options);

$result = file_get_contents('http://www.google.com/recaptcha/api/verify', false, $context);

visit 
http://php.net/manual/en/context.http.php
for more.

adios!

No comments:

Post a Comment