Re: Problems sending $_POST vairable to an ASP page

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 28 Aug 2008, at 23:01, shaun thornburgh wrote:
Date: Thu, 28 Aug 2008 16:24:58 -0500> From: jblanchard@xxxxxxxxxx> To: shaunthornburgh@xxxxxxxxxxx; php-general@xxxxxxxxxxxxx> Subject: RE: Problems sending $_POST vairable to an ASP page> > [snip]> Unfortunately I don't have curl installed on my server.> [/snip]> > Unless you can open a socket or a curl session you will not be able to> post values to a remote page. Curl is your best bet, can it be> installed?> > -- > PHP General Mailing List (http://www.php.net/ )> To unsubscribe, visit: http://www.php.net/unsub.php>
It appears I was wrong, I do have cURL installed!

In that case I'll amend my earlier answer to the following...

<?php
// I can't see in your example where you're building the POST data, but here's an example
$postdata = 'var='.urlencode($value);

if (function_exists('curl_init'))
{
  // Do it with CURL
  $curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, 'http://dmtrk.net/signup.ashx') ;
  curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 30);
  curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($curl_handle, CURLOPT_POST, 1);
  curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $postdata);
  $result = curl_exec($curl_handle);
  curl_close($curl_handle);
}
elseif (function_exists('fsockopen'))
{
  $fp = fsockopen('dmtrk.net', 80, $errno, $errstr, 30);
  if (!$fp)
  {
    $result = 'Connection failed: ['.$errno.'] '.$errstr;
  }
  else
  {
    fwrite($fp, "POST /signup.ashx HTTP/1.1\n");
    fwrite($fp, "Connection: close\n");
    fwrite($fp, "Host: dmtrk.net\n");
    fwrite($fp, "Content-Length: ".strlen($postdata)."\n");
    fwrite($fp, "Content-Type: application/x-www-form-urlencoded\n");
    fwrite($fp, "\n".$postdata."\n");
	
    // Get the status
    $response = fgets($fp);
    $result = (strpos($response, ' 200 ') !== false);

    // Read the rest of the response
    while (!feof($fp))
    {
      $response .= fgets($fp);
    }
    @fclose($fp);

    if (!$result) $result = $response;
  }
}
else
{
  die('No suitable mechanism for POSTing available.');
}
?>

Note that I've not tested this at all, but it should work. Also it would be better wrapped up in a function, but unfortunately I have real work to do today.

-Stut

--
http://stut.net/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux