Sascha: fsockopen fuer https request...

Beitrag lesen

Hallo Eddie,

erstmal danke das Du Dir die Zeit nimmst mir damit weiterzuhelfen.
Habe das Script nochmal neu in den Quelltext kopiert und komischerweise war die Fehlermeldung danach auch verschwunden. ;)
Was es auch immer gewesen ist?!?!...

Naja, ich hab mit diesem Script nochmal ein wenig rumgespielt und bin auch schon fast durch. Jedoch bekomme ich immer noch eine Fehlermeldung die ich nicht so ganz verstehe.

Hier erstmal der von mir modifizierte Code:

//------------------------------
$host = "secure.ibill.com";
$port = 443;
$path = "/cgi-win/ccard/tpcard.exe"; //or .dll, etc. for authnet, etc.

//you will need to setup an array of fields to post with
//then create the post string
$formdata = array ("reqtype" => "authorize","account" => "89598114","password" => "1web4u","saletype" => "sale","cardnum" => "4128000011112222","cardexp" => "0304","noc" => "john doe","address1" => "99anystreet","zipcode" => "12345","amount" => "1.00","crefnum" => "12345test");

//build the post string
foreach($formdata AS $key => $val){
    $poststring.=urlencode($key)."=".urlencode($val)."&";
}

// strip off trailing ampersand
$poststring = substr($poststring, 0, -1);

$fp = fsockopen("ssl://".$host, $port, $errno, $errstr, $timeout = 600);

if(!$fp) {
//error tell us
echo "$errstr ($errno)\n";

} else {
//send the server request
fputs($fp, "POST $path HTTP/1.0\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ".strlen($poststring)."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $poststring."\r\n\r\n");

//loop through the response from the server
while(!feof($fp)) {
$string = @fgets($fp);

$string = strstr($string,"declined");
$string = ereg_replace(""","",$string);

}
//close fp - we are done with it
fclose($fp);
}

$arr = explode(",",$string);

foreach($arr as $elem) {
echo $elem."<br>";
}
//------------------------------

Ok..  also wie schon gesagt, das script funzt soweit, schmeisst mir aber immer folgenden error aus:

Notice: Undefined variable: poststring in /test.php on line 13
==>( $poststring.=urlencode($key)."=".urlencode($val)."&"; )

Verstehen kann ich das allerdings nicht, da $poststring ja Daten enthaelt, ansonsten wuerde das Script ja nichts zurueckliefern?

Danke fuer Deine Hilfe
Sascha