You are here: fsockopen problem « PHP Programming Language « IT news, forums, messages
fsockopen problem

Posted by murd on 05/20/06 15:41

Hi, I am trying to complete a post using fsockopen but I'm getting the
following error:

"Unable to find the socket transport "ssl" - did you forget to enable
it when you configured PHP?

I am running php 5.1.4 with apache 2 on fedora core 4. When I
configured php I did it like this:
../configure --with-apxs2=/usr/sbin/apxs --with-mysql

All I'm trying to achieve is to get a response from the neteller test
server, the response will be an error as the numbers I'm sending it are
garbage, but I'm not bothered about that, I just want to be able to
send the request and get the response back. I've searched google for a
while but can't figure out why my code isn't working, I know there were
problems with windows platforms with php4 but obviously, that is not an
issue here...


Thanks in advance, my code is below...
Angus



<?php
//SIMULATES A (HTTP POST) FORM SUBMISSION
//www.zend.com/zend/spotlight/mimocsumissions.php
//takes 2 parameters: associative array containing data to be sent to
server, DNS or IP of server
//returns $result array with lines of response
function post_it($datastream, $url)
{
//replace http:// with the empty string, get host, get resource
$url = preg_replace("@^https://@i", "", $url);
$host = substr($url, 0, strpos($url, "/"));
$uri = strstr($url, "/");

//construct request body: vars and their values
$reqbody ="";
foreach ($datastream as $key => $val)
{
if (!empty($reqbody))
$reqbody .= "&";
$reqbody .= $key."=".urlencode($val);
}

//construct post request to be sent to server, include size of reqbody
$contentlength = strlen($reqbody);
$reqheader = "POST $uri HTTP/1.0 \r\n";
$reqheader .= "Host: $host\n";
$reqheader .= "User-Agent: PostIt\r\n";
$reqheader .= "Content-Type: application/x-www-form-urlencoded\r\n";
$reqheader .= "Content-Length: $contentlength\r\n\r\n";
$reqheader .= "$reqbody\r\n";

//connect to server, send POST request, read result, close socket
$socket = fsockopen("ssl://".$host, 443, $errno, $errstr);

if (!$socket)
{
echo "host: ".$host."<br>";

echo "<p>&nbsp;</p>";

$result["errno"] = $errno;
$result["errstr"] = $errstr;
return $result;
}
fputs($socket, $reqheader);
while (!feof($socket))
{
$result[] = fgets($socket, 4096);
}
fclose($socket);
return $result;
}
?>

<HTML>
<HEAD>
<TITLE>NETeller Transfer</TITLE><META HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=iso-8859-1">
</HEAD>
<BODY>
<?php
$data["merchant_ID"] = 123;
$data["merch_transid"] = 123;
$data["test"] = 1;
$data["amount"] = 123;
$data["currency"] = "USD";
$data["net_account"] = 123;
$data["secure_id"] = 123;

$result = post_it($data,
"https://www.neteller.com/gateway/netdirectv4.cfm");

if (isset($result["errno"])) {
$errno = $result["errno"];
$errstr = $result["errstr"];
echo "<B>Error $errno</B> $errstr";
exit;
}
else {
for($i = 0; $i < count($result); $i++)
echo $result[$i];
}
?>
</BODY>
</HTML>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация