fsockopen problem

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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...

//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);
    return $result;

<TITLE>NETeller Transfer</TITLE><META HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=iso-8859-1">
        $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";
        else {
            for($i = 0; $i < count($result); $i++)
                echo $result[$i];

Re: fsockopen problem

murd@hotmail.co.uk wrote:
Quoted text here. Click to load it


My guess is that either mod_ssl is not installed for apache or it is
installed but the configuration lines for mod_ssl are commented out in
httpd.conf (like it was on suse9 for me). apxs will only enable ssl
functions in php if mod_ssl is up and running

So check mod_ssl is available + enabled in apache then try recompiling
php with

 ./configure --with-apxs2=/usr/sbin/apxs --with-mysql --enable-ssl


Re: fsockopen problem

tim wrote:

Quoted text here. Click to load it

Wrong. You are getting confused about servers and clients - mod_ssl is what
runs on the server. The OP is talking about the client end of an SSL
connection. I had a quick look at the PHP docs and it doesn't tell you the
option for client SSL. Trying with a copy of 5.0.4 I've got
handy, ./configure --help suggests:

--with-openssl[=DIR]    Include OpenSSL support (requires OpenSSL >= 0.9.6)

YMMV. Alternatively, as a quick hack, set up a stunnel connection.


Re: fsockopen problem

Colin McKinnon wrote:
Quoted text here. Click to load it

I know the difference but I failed to point out the difference clear in
my post and there are good resons in this case to make suggest mod_ssl
is installed.

The OP is going to be submitting details to neteller and I assumed they
will be submitted to him over the web.

When processing banking info over the web its best to have a secure
connection between the web browser->server/php script as well as
between the script/merchant bank. This would need mod_ssl installed in
the server as well as the ssl client functions enabled in php and this
is why I talked about mod_ssl in apache being needed.

Of course I should have said in my post that mod_ssl isnt needed to
enable the the ssl functions in php so thanks for pointing it out.


Re: fsockopen problem

Thank you for the reply....   However, I forgot to mention in my
initial post that if I try it with a normal http post on port 80 it
still throws an error:  Something like:

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

Can someone check to see if the code I've got does actually send the
request and get a response on their system?


Re: fsockopen problem

Eh Lit wrote:
Quoted text here. Click to load it

Its worked ok for ssl and port 80 on my gf's pc. There was a http 400
error but it was only a missing carriage return in $reqheader .= "Host:

My only suggestion is recompile php with --enable-sockets as well as
--with-openssl like Colin said earlier.

The full response from neteller was

<TITLE>NETeller Transfer</TITLE><META HTTP-EQUIV="Content-Type"
CONTENT="text/html; charset=iso-8859-1">
        HTTP/1.1 200 OK
Connection: close
Date: Sun, 21 May 2006 01:00:03 GMT
Content-Type: text/html; charset=UTF-8
Server: Microsoft-IIS/6.0 Geobytes-GeoSelect/
path=/; expires=Mon, 21-May-2007 01:00:03 GMT

<?xml version="1.0" encoding="ISO-8859-1"?><netdirect version="4.0">


Re: fsockopen problem

Quoted text here. Click to load it

I made a big mistake. I thought fsockopen was one of the socket
functions and needed enabling. It isn't. Its one of the network
functions and is always available.

By chance I got the exact same message you had when I tried
fsockopen('http://servername.com ',80) but itr workde when I tried

Quoted text here. Click to load it
way to do a normal http request with fsockopen is using 'tcp://' not
'http://'.....Also tcp:// is assumed if by default if one isn't
specified and http:// isnt recognised.


Site Timeline