mechanical turk submitting external hit with curl

Hi,

rather dry, but I spent a day figuring this out.  The below lets you submit an external MTurk hit via a simple php file.  The file uses Curl.

Hope this helps someone.

<?php

$url = $_GET[‘url’];

$myParams = “assignmentId=” . $_GET[‘assignmentId’] . “&dummy=1″;

if($url==”real”)$url= ‘http://www.mturk.com/mturk/externalSubmit’;
else $url= ‘http://workersandbox.mturk.com/mturk/externalSubmit’;

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “POST”);
curl_setopt($ch,CURLOPT_POST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$myParams);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);

?>