By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,663 Members | 1,398 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,663 IT Pros & Developers. It's quick & easy.

Warning: fgets(): SSL: fatal protocol error

P: n/a
Okay, I am working on a credit card validation script, I have it
working perfectly (saving the return information from the server to a
variable and echoing it for now) other than this weird error on the
fgets() line. I can't seem to figure out the problem, the code is
below, any help is appreciated!

<?php
$host = "secure.authorize.net";
$port = 443;
$path = "/gateway/transact.dll";
$formdata = array ("x_form_post_data_here" => "value");
foreach($formdata AS $key => $val){
$poststring .= urlencode($key) . "=" . urlencode($val) . "&";
}
$poststring = substr($poststring, 0, -1);
$fp = fsockopen("ssl://".$host, $port, $errno, $errstr, $timeout =
30);
if(!$fp){
echo "$errstr ($errno)\n";
}else{
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");
while(!feof($fp)) {
$out_put_string .= fgets($fp, 4096); //<== HERE IS THE ERROR LINE #
}
fclose($fp);
}
echo $out_put_string;
?>
Jul 16 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Adam Bergman wrote:
Okay, I am working on a credit card validation script, I have it
working perfectly (saving the return information from the server to a
variable and echoing it for now) other than this weird error on the
You've forgotten to mention what the error is :)
fgets() line. I can't seem to figure out the problem, the code is
below, any help is appreciated!

<?php
$host = "secure.authorize.net";
$port = 443;
$path = "/gateway/transact.dll";
$formdata = array ("x_form_post_data_here" => "value");
foreach($formdata AS $key => $val){
$poststring .= urlencode($key) . "=" . urlencode($val) . "&";
}
$poststring = substr($poststring, 0, -1);
$fp = fsockopen("ssl://".$host, $port, $errno, $errstr, $timeout =
30);
if(!$fp){
echo "$errstr ($errno)\n";
}else{
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");
while(!feof($fp)) {
$out_put_string .= fgets($fp, 4096); //<== HERE IS THE ERROR LINE #
}
fclose($fp);
}
echo $out_put_string;
?>


--
MeerKat

Jul 16 '05 #2

P: n/a
MeerKat wrote:
Adam Bergman wrote:
Okay, I am working on a credit card validation script, I have it
working perfectly (saving the return information from the server to a
variable and echoing it for now) other than this weird error on the

You've forgotten to mention what the error is :)


OK, now I see it hidden in the subject line... What version of PHP do
you have? SSL is only supported on PHP 4.3 and above.

(apologies for the messed up formatting of this message... stupid
computers...)
fgets() line. I can't seem to figure out the problem, the code is
below, any help is appreciated!

<?php
$host = "secure.authorize.net"; $port = 443; $path =
"/gateway/transact.dll"; $formdata = array ("x_form_post_data_here" =>
"value");
foreach($formdata AS $key => $val){ $poststring .=
urlencode($key) . "=" . urlencode($val) . "&"; } $poststring =
substr($poststring, 0, -1); $fp = fsockopen("ssl://".$host, $port,
$errno, $errstr, $timeout =
30);
if(!$fp){ echo "$errstr ($errno)\n"; }else{ 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");
while(!feof($fp)) { $out_put_string .= fgets($fp, 4096); //<==
HERE IS THE ERROR LINE #
} fclose($fp); } echo $out_put_string;
?>



--
MeerKat

Jul 16 '05 #3

P: n/a
sam
"Adam Bergman" <ad**@a2ztech.net> wrote in message
news:a7*************************@posting.google.co m...
Okay, I am working on a credit card validation script, I have it
working perfectly (saving the return information from the server to a
variable and echoing it for now) other than this weird error on the
fgets() line. I can't seem to figure out the problem, the code is
below, any help is appreciated!

<?php
$host = "secure.authorize.net";
$port = 443;
$path = "/gateway/transact.dll";
$formdata = array ("x_form_post_data_here" => "value");
foreach($formdata AS $key => $val){
$poststring .= urlencode($key) . "=" . urlencode($val) . "&";
}
$poststring = substr($poststring, 0, -1);
$fp = fsockopen("ssl://".$host, $port, $errno, $errstr, $timeout =
30);
Here, you get $fp = null
I don't know a protocol named SSL (Secure Socket Layer)?????
You mean HTTPS. So, change 'ssl' with 'https'.
if(!$fp){
echo "$errstr ($errno)\n";
}else{
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");
while(!feof($fp)) {
$out_put_string .= fgets($fp, 4096); //<== HERE IS THE ERROR LINE #
}
fclose($fp);
}
echo $out_put_string;
?>

Jul 16 '05 #4

P: n/a
On Mon, 15 Sep 2003 21:06:14 -0500, Adam Bergman created an award-winning
crop circle <a7*************************@posting.google.com> , which, when
translated into English, means this:
Okay, I am working on a credit card validation script, I have it
working perfectly (saving the return information from the server to a
variable and echoing it for now) other than this weird error on the
fgets() line.
[...]
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");
while(!feof($fp)) {
$out_put_string .= fgets($fp, 4096); //<== HERE IS THE ERROR LINE #
[...]


My experience has been that, when using fsockopen
to do an HTTP POST, \r\n does not work as a line
terminator. I've been forced to use just \n.

YMMV

The standard says that lines end with \r\n, but somehow
with PHP and fsockopen() that does not work. Here is my
post where I show what I did:

<pa********************************@REMOVE.MEearth link.INVALID>

HTH

Jul 16 '05 #5

P: n/a
The error syntax is in the subject as well as the line number
commented in the code. What more do you want?

MeerKat <li****************@blueyonder.co.uk> wrote in message news:<Lm*****************@news-binary.blueyonder.co.uk>...
Adam Bergman wrote:
Okay, I am working on a credit card validation script, I have it
working perfectly (saving the return information from the server to a
variable and echoing it for now) other than this weird error on the


You've forgotten to mention what the error is :)
fgets() line. I can't seem to figure out the problem, the code is
below, any help is appreciated!

<?php
$host = "secure.authorize.net";
$port = 443;
$path = "/gateway/transact.dll";
$formdata = array ("x_form_post_data_here" => "value");
foreach($formdata AS $key => $val){
$poststring .= urlencode($key) . "=" . urlencode($val) . "&";
}
$poststring = substr($poststring, 0, -1);
$fp = fsockopen("ssl://".$host, $port, $errno, $errstr, $timeout =
30);
if(!$fp){
echo "$errstr ($errno)\n";
}else{
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");
while(!feof($fp)) {
$out_put_string .= fgets($fp, 4096); //<== HERE IS THE ERROR LINE #
}

fclose($fp);
}
echo $out_put_string;
?>

Jul 16 '05 #6

P: n/a
>>RE:SAM
Here, you get $fp = null
I don't know a protocol named SSL (Secure Socket Layer)?????
You mean HTTPS. So, change 'ssl' with 'https'.
Actually, HTTPS is an unknown protocol you MUST use SSL (see the
fsockopen() function reference on PHP.net). If I use HTTPS as the
protocol I get all sorts of errors.
RE:GARY
My experience has been that, when using fsockopen
to do an HTTP POST, \r\n does not work as a line
terminator. I've been forced to use just \n.


I tried removing all the \r's from my headers however it did not
change the error message I am getting. I did however, set the text
size of the error to 1pt (with style), made it the background color,
and used the visibility style tag to hide the layer that the error
mes. is on so at least people can't see it.

I AM receiving the correct response from the server, I just get that
weird error.
Jul 16 '05 #7

P: n/a
Adam Bergman wrote:
The error syntax is in the subject as well as the line number
commented in the code. What more do you want?
Sorry. Forgive me. Please.

Are you using a PHP version below 4.3?
MeerKat <li****************@blueyonder.co.uk> wrote in message news:<Lm*****************@news-binary.blueyonder.co.uk>...
Adam Bergman wrote:

Okay, I am working on a credit card validation script, I have it
working perfectly (saving the return information from the server to a
variable and echoing it for now) other than this weird error on the


You've forgotten to mention what the error is :)

fgets() line. I can't seem to figure out the problem, the code is
below, any help is appreciated!

<?php
$host = "secure.authorize.net";
$port = 443;
$path = "/gateway/transact.dll";
$formdata = array ("x_form_post_data_here" => "value");
foreach($formdata AS $key => $val){
$poststring .= urlencode($key) . "=" . urlencode($val) . "&";
}
$poststring = substr($poststring, 0, -1);
$fp = fsockopen("ssl://".$host, $port, $errno, $errstr, $timeout =
30);
if(!$fp){
echo "$errstr ($errno)\n";
}else{
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");
while(!feof($fp)) {
$out_put_string .= fgets($fp, 4096); //<== HERE IS THE ERROR LINE #
}


fclose($fp);
}
echo $out_put_string;
?>


--
MeerKat

Jul 16 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.