TLS 1.2 and HTTP/1.1 upgrade (PHP fsockopen)

TLS 1.2 and HTTP/1.1 upgrade (PHP fsockopen)

by stn user -
Number of replies: 0

Hello all,

I am new to Moodle, PHP & PayPal and trying to figure it out whether I need to upgrade TLS or not according to the following PayPal article: https://www.paypal-knowledge.com/infocenter/index?page=content&id=FAQ1914

To verify the system I modified ipn.php file to use "www.tlstest.paypal.com" endpoint as follows:

$header = '';
$header .= "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: www.tlstest.paypal.com\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$paypaladdr = 'www.tlstest.paypal.com';
$fp = fsockopen('ssl://'.$paypaladdr, 443, $errno, $errstr, 30);
fputs ($fp, $header.$req);
while (!feof($fp)) {
    $result = fgets($fp, 1024);
    here i added code to write the $result to a log file 
    if (strcmp($result, "VERIFIED") == 0) {          // VALID PAYMENT!
          the code never gets here
     }
------------------------------------------------------------------------------------------------------------
}

Then I try buying a course.  After paying in PayPal and returning to the course, I receive the following error message in the user interface right away:  "Thank you for your payment!  Unfortunately your payment has not fully processed, and you are not yet registered to access the course".

At this point, the transaction is not tracked in mdl_enrol_paypal table and I am not able to access the course.

In the log file, I see these message right away:

2017-05-02 11:38:06 173.0.81.1 PayPal result: HTTP/1.1  200
OK
2017-05-02 11:38:06 173.0.81.1 PayPal result: Content-Type: text/html
2017-05-02 11:38:06 173.0.81.1 PayPal result: Content-Length: 20
2017-05-02 11:38:06 173.0.81.1 PayPal result: Date: Tue, 02 May 2017 11:37:54 GMT
2017-05-02 11:38:06 173.0.81.1 PayPal result: Connection: keep-alive
2017-05-02 11:38:06 173.0.81.1 PayPal result:

 Same response again (7 times):

 2017-05-02 11:39:33 173.0.81.1 PayPal result: HTTP/1.1  200
OK
2017-05-02 11:39:33 173.0.81.1 PayPal result: Content-Type: text/html
2017-05-02 11:39:33 173.0.81.1 PayPal result: Content-Length: 20
2017-05-02 11:39:33 173.0.81.1 PayPal result: Date: Tue, 02 May 2017 11:39:21 GMT
2017-05-02 11:39:33 173.0.81.1 PayPal result: Connection: keep-alive
2017-05-02 11:39:33 173.0.81.1 PayPal result:
 
2017-05-02 11:40:15 173.0.81.1 PayPal result: HTTP/1.1  200 OK
2017-05-02 11:40:15 173.0.81.1 PayPal result: Content-Type: text/html
2017-05-02 11:40:15 173.0.81.1 PayPal result: Content-Length: 20
2017-05-02 11:40:15 173.0.81.1 PayPal result: Date: Tue, 02 May 2017 11:40:03 GMT
2017-05-02 11:40:15 173.0.81.1 PayPal result: Connection: keep-alive
2017-05-02 11:40:15 173.0.81.1 PayPal result:
 
2017-05-02 11:40:48 173.0.81.1 PayPal result: HTTP/1.1  200 OK
2017-05-02 11:40:48 173.0.81.1 PayPal result: Content-Type: text/html
2017-05-02 11:40:48 173.0.81.1 PayPal result: Content-Length: 20
2017-05-02 11:40:48 173.0.81.1 PayPal result: Date: Tue, 02 May 2017 11:40:36 GMT
2017-05-02 11:40:48 173.0.81.1 PayPal result: Connection: keep-alive
2017-05-02 11:40:48 173.0.81.1 PayPal result:
 
2017-05-02 11:41:54 173.0.81.1 PayPal result: HTTP/1.1  200 OK
2017-05-02 11:41:54 173.0.81.1 PayPal result: Content-Type: text/html
2017-05-02 11:41:54 173.0.81.1 PayPal result: Content-Length: 20
2017-05-02 11:41:54 173.0.81.1 PayPal result: Date: Tue, 02 May 2017 11:41:42 GMT
2017-05-02 11:41:54 173.0.81.1 PayPal result: Connection: keep-alive
2017-05-02 11:41:54 173.0.81.1 PayPal result:
 
2017-05-02 11:43:57 173.0.81.1 PayPal result: HTTP/1.1  200 OK
2017-05-02 11:43:57 173.0.81.1 PayPal result: Content-Type: text/html
2017-05-02 11:43:57 173.0.81.1 PayPal result: Content-Length: 20
2017-05-02 11:43:57 173.0.81.1 PayPal result: Date: Tue, 02 May 2017 11:43:45 GMT
2017-05-02 11:43:57 173.0.81.1 PayPal result: Connection: keep-alive
2017-05-02 11:43:57 173.0.81.1 PayPal result:
 
2017-05-02 11:44:52 173.0.81.1 PayPal result: HTTP/1.1  200 OK
2017-05-02 11:44:52 173.0.81.1 PayPal result: Content-Type: text/html
2017-05-02 11:44:52 173.0.81.1 PayPal result: Content-Length: 20
2017-05-02 11:44:52 173.0.81.1 PayPal result: Date: Tue, 02 May 2017 11:44:40 GMT
2017-05-02 11:44:52 173.0.81.1 PayPal result: Connection: keep-alive
2017-05-02 11:44:52 173.0.81.1 PayPal result:

 After a couple of minutes I see "PayPal_Connection_OK":

2017-05-02 11:46:26 173.0.81.1 PayPal result: PayPal_Connection_OK
2017-05-02 11:46:38 173.0.81.1 PayPal result: HTTP/1.1  200
OK
2017-05-02 11:46:38 173.0.81.1 PayPal result: Content-Type: text/html
2017-05-02 11:46:38 173.0.81.1 PayPal result: Content-Length: 20
2017-05-02 11:46:38 173.0.81.1 PayPal result: Date: Tue, 02 May 2017 11:46:26 GMT
2017-05-02 11:46:38 173.0.81.1 PayPal result: Connection: keep-alive
2017-05-02 11:46:38 173.0.81.1 PayPal result:

 Then again "PayPal_Connection_OK" (7 times):

2017-05-02 11:47:53 173.0.81.1 PayPal result: PayPal_Connection_OK
2017-05-02 11:48:35 173.0.81.1 PayPal result: PayPal_Connection_OK
2017-05-02 11:49:08 173.0.81.1 PayPal result: PayPal_Connection_OK
2017-05-02 11:50:14 173.0.81.1 PayPal result: PayPal_Connection_OK
2017-05-02 11:52:17 173.0.81.1 PayPal result: PayPal_Connection_OK
2017-05-02 11:53:12 173.0.81.1 PayPal result: PayPal_Connection_OK
2017-05-02 11:54:58 173.0.81.1 PayPal result: PayPal_Connection_OK

After a while the transaction is tracked into the mdl_enrol_paypal table and I am able to access the course.

I am a little confused why is taking so long to receive the "PayPal_Connection_OK" message and why there are 8 responses instead of 1.

How can I make sure everything will work fine after July 1st?

I came across the following article https://github.com/paypal/TLS-update#php which also explains how to test but I do not see any references to “curl” libraries in the ipn.php page.  The PayPal connection is established via “fsockopen()”.  Does this mean I am not using "curl" at all?  Is "fsockopen()" using "curl" in the back end?

Any help would be very much appreciated.

Thank you in advance.

Average of ratings: -