<? Php Class paypal { Var $ ipn_data = array (); // array contains the POST values for IPN Var $ fields = array (); // parameters of the form submitted to Paypal, for example, item_name = iPhone 6, quantity = 1, amount = 499, currency_code = USD, etc, // Initialization is required before IPN verification is called. Var $ paypal_url = 'https: // response Function validate_ipn () {// verify IPN // Parse the paypal URL $ Url_par = parse_url ($ this-> paypal_url ); // Generate the post string from the _ POST vars aswell as load // _ POST vars into an arry so we can play with them from the calling // Script. $ Post_str = ''; Foreach ($ _ POST as $ field => $ value ){ $ This-> ipn_data ["$ field"] = $ value; $ Post_str. = $ field. '='. urlencode (stripslashes ($ value )).'&'; } $ Post_str. = "cmd = _ policy-validate"; // append ipn command // Open the connection to paypal $ Fp = fsockopen ($ url_par [host], "80", $ errnum, $ errstr, 30 ); If (! $ Fp ){ // Cocould not open the connection. Return false; } Else { // Post the data back to paypal Fputs ($ fp, "POST". $ url_par [path]. "HTTP/1.1 \ r \ n "); Fputs ($ fp, "Host:". $ url_par [host]. "\ r \ n "); Fputs ($ fp, "Content-type: application/x-www-form-urlencoded \ r \ n "); Fputs ($ fp, "Content-length:". strlen ($ post_str). "\ r \ n "); Fputs ($ fp, "Connection: close \ r \ n "); Fputs ($ fp, $ post_str. "\ r \ n "); // Loop through the response from the server and append to variable While (! Feof ($ fp )){ $ This-> validate_ipn_response. = fgets ($ fp, 1024 ); } Fclose ($ fp); // close connection } If (eregi ("VERIFIED", $ this-> validate_ipn_response )){ Return true; } Else { Return false; } } } ?> |