Re: [PHP] Problems sending $_POST vairable to an ASP page

2008-08-29 Thread Stut

On 28 Aug 2008, at 22:17, shaun thornburgh wrote:

Hi guys,
I need to send post variables to an ASP page. I have the following  
code which isn't producing any errors but isn't working either:


foreach($_POST['newsletter-group'] as $key = $value) 
{ $_POST['addressbookid'] = $value; $out = POST /signup.ashx;  $fp  
= fsockopen(dmtrk.net, 80, $errno, $errstr, 30); if (!$fp) {  echo  
$errstr ($errno)br /\n; } else {   fputs($fp, $out . \r 
\n);  }  fclose($fp); }


Can anyone tell me what I am doing wrong please?



?php
$result = false;

// I can't see in your example where you're building the POST data,  
but here's an example

$postdata = 'var='.urlencode($value);

$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;
}

// At this point $result will either be === true or it will contain an  
error message


// Please don't ask a question again without doing a reasonable amount  
of research first. In this case that would be the HTTP spec and the  
PHP socket function documentation. This was not difficult!

?

-Stut

--
http://stut.net

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



Re: [PHP] Problems sending $_POST vairable to an ASP page

2008-08-29 Thread Stut

On 28 Aug 2008, at 23:01, shaun thornburgh wrote:
Date: Thu, 28 Aug 2008 16:24:58 -0500 From: [EMAIL PROTECTED]  
To: [EMAIL PROTECTED]; php-general@lists.php.net  
Subject: RE: [PHP] 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



RE: [PHP] Problems sending $_POST vairable to an ASP page

2008-08-28 Thread Jay Blanchard
[snip]
I need to send post variables to an ASP page. I have the following code
which isn't producing any errors but isn't working either:
 
foreach($_POST['newsletter-group'] as $key = $value){
$_POST['addressbookid'] = $value; $out = POST /signup.ashx;  $fp =
fsockopen(dmtrk.net, 80, $errno, $errstr, 30); if (!$fp) {  echo
$errstr ($errno)br /\n; } else {   fputs($fp, $out . \r\n);  }
fclose($fp); }
 
Can anyone tell me what I am doing wrong please?
[/snip]

http://www.php.net/curl


there was just a thread on this within the past week.

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



Re: [PHP] Problems sending $_POST vairable to an ASP page

2008-08-28 Thread Ólafur Waage
IIRC ASP cant recive PHP $_POST variables but it can recive HTML post
from forms.

If you want to send variables to another language. You can try via a
get variable. Dont know if the items you want to send are safe to send
over though.

Ólafur Waage

2008/8/28 shaun thornburgh [EMAIL PROTECTED]:
 Hi guys,
 I need to send post variables to an ASP page. I have the following code which 
 isn't producing any errors but isn't working either:

 foreach($_POST['newsletter-group'] as $key = $value){ 
 $_POST['addressbookid'] = $value; $out = POST /signup.ashx;  $fp = 
 fsockopen(dmtrk.net, 80, $errno, $errstr, 30); if (!$fp) {  echo $errstr 
 ($errno)br /\n; } else {   fputs($fp, $out . \r\n);  }  fclose($fp); }

 Can anyone tell me what I am doing wrong please?
 _
 Get Hotmail on your mobile from Vodafone
 http://clk.atdmt.com/UKM/go/107571435/direct/01/

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



RE: [PHP] Problems sending $_POST vairable to an ASP page

2008-08-28 Thread shaun thornburgh




 Date: Thu, 28 Aug 2008 16:21:19 -0500 From: [EMAIL PROTECTED] To: [EMAIL 
 PROTECTED]; php-general@lists.php.net Subject: RE: [PHP] Problems sending 
 $_POST vairable to an ASP page  [snip] I need to send post variables to an 
 ASP page. I have the following code which isn't producing any errors but 
 isn't working either:  foreach($_POST['newsletter-group'] as $key = 
 $value){ $_POST['addressbookid'] = $value; $out = POST /signup.ashx; $fp 
 = fsockopen(dmtrk.net, 80, $errno, $errstr, 30); if (!$fp) { echo 
 $errstr ($errno)br /\n; } else { fputs($fp, $out . \r\n); } 
 fclose($fp); }  Can anyone tell me what I am doing wrong please? [/snip] 
  http://www.php.net/curl   there was just a thread on this within the 
 past week.  --  PHP General Mailing List (http://www.php.net/) To 
 unsubscribe, visit: http://www.php.net/unsub.php 
 
Hi Jay,
 
Unfortunately I don't have curl installed on my server.
 
 
_
Make a mini you on Windows Live Messenger!
http://clk.atdmt.com/UKM/go/107571437/direct/01/

RE: [PHP] Problems sending $_POST vairable to an ASP page

2008-08-28 Thread Jay Blanchard
[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



RE: [PHP] Problems sending $_POST vairable to an ASP page

2008-08-28 Thread shaun thornburgh


 Date: Thu, 28 Aug 2008 16:24:58 -0500 From: [EMAIL PROTECTED] To: [EMAIL 
 PROTECTED]; php-general@lists.php.net Subject: RE: [PHP] 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!
_
Win New York holidays with Kellogg’s  Live Search
http://clk.atdmt.com/UKM/go/107571440/direct/01/