Re: [PHP] Problems sending $_POST vairable to an ASP page
- From: stuttle@xxxxxxxxx (Stut)
- Date: Fri, 29 Aug 2008 08:38:27 +0100
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
.
- Prev by Date: Re: [PHP] Re: Variable name as a string
- Next by Date: Braindead
- Previous by thread: Re: [PHP] ASCII Captcha
- Next by thread: Braindead
- Index(es):