Warning: fgets(): SSL: fatal protocol error

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Adam Bergman

    Warning: fgets(): SSL: fatal protocol error

    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.authori ze.net";
    $port = 443;
    $path = "/gateway/transact.dll";
    $formdata = array ("x_form_post_d ata_here" => "value");
    foreach($formda ta AS $key => $val){
    $poststring .= urlencode($key) . "=" . urlencode($val) . "&";
    }
    $poststring = substr($poststr ing, 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($posts tring)."\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

    #2
    Re: Warning: fgets(): SSL: fatal protocol error

    Adam Bergman wrote:
    [color=blue]
    > 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[/color]

    You've forgotten to mention what the error is :)
    [color=blue]
    > fgets() line. I can't seem to figure out the problem, the code is
    > below, any help is appreciated!
    >
    > <?php
    > $host = "secure.authori ze.net";
    > $port = 443;
    > $path = "/gateway/transact.dll";
    > $formdata = array ("x_form_post_d ata_here" => "value");
    > foreach($formda ta AS $key => $val){
    > $poststring .= urlencode($key) . "=" . urlencode($val) . "&";
    > }
    > $poststring = substr($poststr ing, 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($posts tring)."\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 ;
    > ?>[/color]

    --
    MeerKat

    Comment

    • MeerKat

      #3
      Re: Warning: fgets(): SSL: fatal protocol error

      MeerKat wrote:
      [color=blue]
      > Adam Bergman wrote:
      >[color=green]
      >> 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[/color]
      >
      >
      > You've forgotten to mention what the error is :)[/color]

      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...)
      [color=blue][color=green]
      >> fgets() line. I can't seem to figure out the problem, the code is
      >> below, any help is appreciated!
      >>
      >> <?php
      >> $host = "secure.authori ze.net"; $port = 443; $path =
      >> "/gateway/transact.dll"; $formdata = array ("x_form_post_d ata_here" =>
      >> "value");
      >> foreach($formda ta AS $key => $val){ $poststring .=
      >> urlencode($key) . "=" . urlencode($val) . "&"; } $poststring =
      >> substr($poststr ing, 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($posts tring)."\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 ;
      >> ?>[/color]
      >
      >[/color]

      --
      MeerKat

      Comment

      • sam

        #4
        Re: Warning: fgets(): SSL: fatal protocol error

        "Adam Bergman" <adam@a2ztech.n et> wrote in message
        news:a7168bd.03 09151806.7bf1f1 ca@posting.goog le.com...[color=blue]
        > 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.authori ze.net";
        > $port = 443;
        > $path = "/gateway/transact.dll";
        > $formdata = array ("x_form_post_d ata_here" => "value");
        > foreach($formda ta AS $key => $val){
        > $poststring .= urlencode($key) . "=" . urlencode($val) . "&";
        > }
        > $poststring = substr($poststr ing, 0, -1);
        > $fp = fsockopen("ssl://".$host, $port, $errno, $errstr, $timeout =
        > 30);[/color]

        Here, you get $fp = null
        I don't know a protocol named SSL (Secure Socket Layer)?????
        You mean HTTPS. So, change 'ssl' with 'https'.
        [color=blue]
        > 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($posts tring)."\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 ;
        > ?>[/color]


        Comment

        • Gary Petersen

          #5
          Re: Warning: fgets(): SSL: fatal protocol error

          On Mon, 15 Sep 2003 21:06:14 -0500, Adam Bergman created an award-winning
          crop circle <a7168bd.030915 1806.7bf1f1ca@p osting.google.c om>, which, when
          translated into English, means this:
          [color=blue]
          > 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($posts tring)."\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 #
          > [...][/color]

          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:

          <pan.2003.08.23 .05.18.48.31873 0.493@REMOVE.ME earthlink.INVAL ID>

          HTH

          Comment

          • Adam Bergman

            #6
            Re: Warning: fgets(): SSL: fatal protocol error

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

            MeerKat <liquidlaughter 2000@blueyonder .co.uk> wrote in message news:<Lmy9b.228 1$BS2.1351@news-binary.blueyond er.co.uk>...[color=blue]
            > Adam Bergman wrote:
            >[color=green]
            > > 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[/color]
            >
            > You've forgotten to mention what the error is :)
            >[color=green]
            > > fgets() line. I can't seem to figure out the problem, the code is
            > > below, any help is appreciated!
            > >
            > > <?php
            > > $host = "secure.authori ze.net";
            > > $port = 443;
            > > $path = "/gateway/transact.dll";
            > > $formdata = array ("x_form_post_d ata_here" => "value");
            > > foreach($formda ta AS $key => $val){
            > > $poststring .= urlencode($key) . "=" . urlencode($val) . "&";
            > > }
            > > $poststring = substr($poststr ing, 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($posts tring)."\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 #
            > > }[/color]
            > fclose($fp);[color=green]
            > > }
            > > echo $out_put_string ;
            > > ?>[/color][/color]

            Comment

            • Adam Bergman

              #7
              Re: Warning: fgets(): SSL: fatal protocol error

              >>RE:SAM[color=blue][color=green]
              >>Here, you get $fp = null
              >>I don't know a protocol named SSL (Secure Socket Layer)?????
              >>You mean HTTPS. So, change 'ssl' with 'https'.[/color][/color]

              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.
              [color=blue][color=green]
              >>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.[/color][/color]

              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.

              Comment

              • MeerKat

                #8
                Re: Warning: fgets(): SSL: fatal protocol error

                Adam Bergman wrote:
                [color=blue]
                > The error syntax is in the subject as well as the line number
                > commented in the code. What more do you want?[/color]

                Sorry. Forgive me. Please.

                Are you using a PHP version below 4.3?
                [color=blue]
                > MeerKat <liquidlaughter 2000@blueyonder .co.uk> wrote in message news:<Lmy9b.228 1$BS2.1351@news-binary.blueyond er.co.uk>...
                >[color=green]
                >>Adam Bergman wrote:
                >>
                >>[color=darkred]
                >>>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[/color]
                >>
                >>You've forgotten to mention what the error is :)
                >>
                >>[color=darkred]
                >>>fgets() line. I can't seem to figure out the problem, the code is
                >>>below, any help is appreciated!
                >>>
                >>><?php
                >>>$host = "secure.authori ze.net";
                >>>$port = 443;
                >>>$path = "/gateway/transact.dll";
                >>>$formdata = array ("x_form_post_d ata_here" => "value");
                >>> foreach($formda ta AS $key => $val){
                >>> $poststring .= urlencode($key) . "=" . urlencode($val) . "&";
                >>> }
                >>>$poststrin g = substr($poststr ing, 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($posts tring)."\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 #
                >>> }[/color]
                >>
                >> fclose($fp);
                >>[color=darkred]
                >>>}
                >>>echo $out_put_string ;
                >>>?>[/color][/color][/color]

                --
                MeerKat

                Comment

                Working...