fsockopen() help

Post here if you are having problems with your account or web site.

fsockopen() help

Postby MasterZ on Sat Apr 22, 2006 1:02 pm

I'm having trouble with my code

Code: Select all
$fp = fsockopen ('www.eliteweaver.co.uk/testing/ipntest.php', 80, $errno, $errstr, 30);


it is returning this error


Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known in /home2/etmadmin/public_html/zenorsoft/ipn-processing.php on line 20

Warning: fsockopen() [function.fsockopen]: unable to connect to www.eliteweaver.co.uk/testing/ipntest.php:80 (Unknown error) in /home2/etmadmin/public_html/zenorsoft/ipn-processing.php on line 20


I have verified that the website address works, but I'm still getting that error.

if I try

Code: Select all
$fp = fsockopen ('http://www.eliteweaver.co.uk/testing/ipntest.php', 80, $errno, $errstr, 30);



that returns this error

Warning: fsockopen() [function.fsockopen]: unable to connect to http://www.eliteweaver.co.uk/testing/ipntest.php:80 (Unable to find the socket transport "http" - did you forget to enable it when you configured PHP?) in /home2/etmadmin/public_html/zenorsoft/ipn-processing.php on line 20



the code looks correct from everything I can lookup, so is this a server problem? Is there something I need to do to work around this? Any ideas?
MasterZ
Registered User
 
Posts: 20
Joined: Tue Jan 10, 2006 7:59 pm

Postby guitrspaz on Sun Apr 23, 2006 12:19 pm

What exactly are you trying to do?
guitrspaz
Registered User
 
Posts: 2
Joined: Sun Apr 23, 2006 12:18 pm
Location: Baltimore

Postby MasterZ on Sun Apr 23, 2006 6:33 pm

get a paypal IPN script to work. IT notifies my site when paypal successfully clears a transaction
MasterZ
Registered User
 
Posts: 20
Joined: Tue Jan 10, 2006 7:59 pm

Postby guitrspaz on Sun Apr 23, 2006 10:47 pm

We looked at the fsockopen info and you might want to try using the ssl:// or tsl:// protocol instead of http://. If that doesn't work, post again.
guitrspaz
Registered User
 
Posts: 2
Joined: Sun Apr 23, 2006 12:18 pm
Location: Baltimore

Postby MasterZ on Tue Apr 25, 2006 12:12 pm

ssl:// didn't work



Warning: fsockopen() [function.fsockopen]: unable to connect to ssl://www.eliteweaver.co.uk/testing/ipntest.php:80 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?) in /home2/etmadmin/public_html/zenorsoft/ipn-processing.php on line 20
MasterZ
Registered User
 
Posts: 20
Joined: Tue Jan 10, 2006 7:59 pm

Postby UNFLUX on Tue Apr 25, 2006 12:43 pm

unfortunately, without the script or some other background as to what it is you are doing, it's really difficult to get you the right solution. Where does the script come from? is it one you wrote, or from paypal? more information is needed so we can get this resolved for you quickly.
User avatar
UNFLUX
Media Director
 
Posts: 238
Joined: Fri Jun 25, 2004 9:19 pm

Postby MasterZ on Tue Apr 25, 2006 12:47 pm

i'm including the entire script. The outline comes from paypal. The link is currently not to paypal, but a website that tests these paypal scripts without having to charge my account for every test.

Code: Select all
<?php
include('head.php');

$bad_txn = 0;
$reason = "";
$date = date(n);

// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) {
   $value = urlencode(stripslashes($value));
   $req .= "&$key=$value";
}

// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('http://www.eliteweaver.co.uk/testing/ipntest.php', 80, $errno, $errstr, 30);

// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];

if (!$fp) {
   // HTTP ERROR
   $bad_txn = 1;
   $reason .= "HTTP ERROR";
} else {
   fputs ($fp, $header . $req);
   while (!feof($fp)) {
      $res = fgets ($fp, 1024);
      if (strcmp ($res, "VERIFIED") == 0) {
         // check the payment_status is Completed
         if($payment_status == "Completed")
         {
            // check that txn_id has not been previously processed
            $query = "SELECT product_id FROM zs_purchase_log WHERE txn_id = '$txn_id' AND status = 'Completed'";
            $rs = my_query($query);
            if(mysql_num_rows())
            {
               // Transaction already processed
               $bad_txn = 1;
               $reason .= "Duplicate Transaction ID<br>";
            };
            // check that receiver_email is your Primary PayPal email
            if($receiver_email != 'jonzenor@gmail.com')
            {
               $bad_txn = 1;
               $reason .= "Invalid receiver email address<br>";
            };
            // check that payment_amount/payment_currency are correct
            $query = "SELECT product_price FROM zs_products WHERE product_code = '$item_number'";
            $rs = my_query($query);
            while($row = mysql_fetch_array($rs))
            {
               $chk_price = $row['product_price'];
            };
            $query = "SELECT user_discount FROM zs_users WHERE username = '$payer_email'";
            $rs = my_query($query);
            while($row = mysql_fetch_array($rs))
            {
               $chk_discount = $row['user_discount'];
            };
            $discount_prcnt = ($chk_discount / 100);
            $discount = ($chk_price * $discount_prcnt);
            $total = ($chk_price - $discount);
            if($payment_amount != $total || $payment_currency != 'USD')
            {
               $bad_txn = 1;
               $reason .= "Bad Payment Data<br>";
            };
         };
         // process payment
         if($bad_txn == 0)
         {
            $query = "SELECT txn_id FROM zs_purchase_log WHERE txn_id = '$txn_id'";
            $rs = my_query($query);
            if(mysql_num_rows($rs))
            {
               $type='update';
            }else{
               $type='new';
            };
               if($type == 'new')
            {
               $query = "INSERT INTO zs_purchase_log (product_code, payment_status, payment_amount, txn_id, username, purchase_date) VALUES ('$item_number', '$payment_status', '$payment_amount', '$txn_id', '$username', '$date')";
               $rs = my_query($query);
            };
            if($type == 'update');
            {
               $query = "UPDATE zs_purchase_log SET product_code = '$product_code', payment_status = '$payment_status', payment_amount = '$payment_amount', username = '$payer_email', purchase_date = '$date' WHERE txn_id = '$txn_id'";
               $rs = my_query($query);
            };
         };               
      }else if (strcmp ($res, "INVALID") == 0) {
         // log for manual investigation
         $bad_txn = 1;
         $reason .= "PayPal says INVALID<br>";
      }
   }
   fclose ($fp);
}

if($bad_txn == 1)
{
   $query = "INSERT INTO zs_bad_txn (item_name, item_number, payment_status, payment_amount, payment_currency, txn_id, receiver_email, payer_email, reason) VALUES ('$item_name', '$item_number', '$payment_status', '$payment_amount', '$payment_currency', '$txn_id', '$receiver_email', '$payer_email', '$reason')";
   $rs = my_query($query);
};
include('foot.php');
?>
MasterZ
Registered User
 
Posts: 20
Joined: Tue Jan 10, 2006 7:59 pm

Postby MasterZ on Tue Apr 25, 2006 12:51 pm

this is supposed to be a 3 way transaction, info sent to me, I send info back to verify that nothing was changed, and then paypal sends back a verify or invalid response and my script processes it from there.
MasterZ
Registered User
 
Posts: 20
Joined: Tue Jan 10, 2006 7:59 pm

Postby Bigwebmaster on Tue Apr 25, 2006 4:34 pm

I have only skimmed over your code, but I believe the problem might be you are using it wrong. This code:

Code: Select all
$fp = fsockopen ('www.eliteweaver.co.uk/testing/ipntest.php', 80, $errno, $errstr, 30);


I don't believe it is looking for a full URL there, as all that part does is translate the domain to the actual IP address. So when you put a /testing/ipntest.php on the end, that part is probably causing the problem. Try using this code:

Code: Select all
$fp = fsockopen ('www.eliteweaver.co.uk', 80, $errno, $errstr, 30);


or actually use the IP address of that server and put:

Code: Select all
$fp = fsockopen ('66.111.61.145', 80, $errno, $errstr, 30);
UNFLUX.NET SUPPORT
User avatar
Bigwebmaster
Technical Director
 
Posts: 109
Joined: Sun Jun 27, 2004 10:54 pm

Postby Bigwebmaster on Tue Apr 25, 2006 4:41 pm

And I am just guessing here, but since you are trying ot use it on the test server you might need to temporarly change this line:

Code: Select all
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";


to

Code: Select all
$header .= "POST /testing/ipntest.php HTTP/1.0\r\n";
UNFLUX.NET SUPPORT
User avatar
Bigwebmaster
Technical Director
 
Posts: 109
Joined: Sun Jun 27, 2004 10:54 pm

Postby MasterZ on Wed Apr 26, 2006 6:49 am

I got it to run without any errors, but it still isn't working right. I'll have to do some more testing after work to see where the problem is. Thanks guys.
MasterZ
Registered User
 
Posts: 20
Joined: Tue Jan 10, 2006 7:59 pm

Postby MasterZ on Wed Apr 26, 2006 3:27 pm

I found something even better!

Pay Pal has an official test site called the Sandbox (http://www.sandbox.paypal.com) that lets you test almost everything that you can do in paypal and allows you to create multiple dummy accounts to test payments with. It works great and it helped me get my script to fully work.

And it's FREE!!
MasterZ
Registered User
 
Posts: 20
Joined: Tue Jan 10, 2006 7:59 pm

Postby UNFLUX on Wed Apr 26, 2006 3:40 pm

:beam:
User avatar
UNFLUX
Media Director
 
Posts: 238
Joined: Fri Jun 25, 2004 9:19 pm

Postby Bigwebmaster on Wed Apr 26, 2006 6:43 pm

I am happy everything fully works for you now! I am curious, did the suggestion I made above help you any? Or what did you do to resolve the initial problem. Just something I would like to know for future reference.

Thanks!
UNFLUX.NET SUPPORT
User avatar
Bigwebmaster
Technical Director
 
Posts: 109
Joined: Sun Jun 27, 2004 10:54 pm


Return to Technical Support

Who is online

Users browsing this forum: MSN [Bot], Yahoo [Bot] and 1 guest

cron