Jump to content


Photo

fp is not valid PHP


  • This topic is locked This topic is locked
8 replies to this topic

#1 Guest(old)

Guest(old)

    Junior Member

  • Members
  • 312 posts

Posted 24 November 2002 - 01:17 AM

Hi,
I pretty much cut and pasted the php code, then added my MySQL bit where needed, but I am getting errors related to the fp.
line 17: $fp = fsockopen ("www.paypal.com", 80, $errno, $errstr, 30);

================Warnings from my IPN page=================
Warning: feof(): 2 is not a valid File-Handle resource in /home/javajim/sonlightdevelopment-www/cartLite/ppAccept.php on line 42

Warning: fgets(): 2 is not a valid File-Handle resource in /home/javajim/sonlightdevelopment-www/cartLite/ppAccept.php on line 43

Warning: fclose(): 2 is not a valid File-Handle resource in /home/javajim/sonlightdevelopment-www/cartLite/ppAccept.php on line 66

==============================================

line 42: while (!feof($fp)) {
line 43: $res = fgets ($fp, 1024);
line 66: fclose ($fp);


I am stumped HELP!
Thanks in advance!
James

#2 dperry

dperry

    Newbie

  • Members
  • Pip
  • 9 posts

Posted 24 November 2002 - 07:51 AM

James,

Try this test below to see if you are able to get a connection.

<?php
$fp = fsockopen ("www.paypal.com", 80, $errno, $errstr, 30);
if($fp)
{
echo "<br>PayPal connection confirmed!<br>";
}
elseif(!$fp)
{
echo "<br>PayPal cannot be contacted!<br><br>Error Number: $errno<br>Error String: $errstr<br>";
}
?>

Dave Perry

#3 Guest(old)

Guest(old)

    Junior Member

  • Members
  • 312 posts

Posted 24 November 2002 - 09:10 AM

Thanks Dave,
Yeah that works fine, however I am still throwing errors.....
I tried to add the headers length to the fputs:
============
fputs ($fp, $header, strlen($header));
while (!feof($fp)) {
============

The script I copied from paypal (which was failing as well) for PHP had this line 41 reading:
============
fputs ($fp, $header . $req);
============

I am still getting same errors!

Any ideas?

TIA,
James

#4 dperry

dperry

    Newbie

  • Members
  • Pip
  • 9 posts

Posted 24 November 2002 - 12:33 PM

James,

Could you post the code you are using. There may be something else in your code that is causing the problem.

Dave

#5 Guest(old)

Guest(old)

    Junior Member

  • Members
  • 312 posts

Posted 24 November 2002 - 01:40 PM

<PRE>

<?php
//INCLUDE('pathToConfig.php'); //connection vars
//INCLUDE('pathToLogFile.php'); // logging to see if the page is hit
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($HTTP_POST_VARS 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";
$header .= $req;
$fp = fsockopen ("www.paypal.com", 80, $errno, $errstr, 30);

// assign posted variables to local variables
// note: additional IPN variables also available -- see IPN documentation
$item_name = $_POST['item_name'];
$receiver_email = $_POST['receiver_email'];
$item_number = $_POST['item_number'];
$invoice = $_POST['invoice'];
$status = $_POST['payment_status'];
$payment_gross = $_POST['payment_gross'];
$txn_id = $_POST['txn_id'];
$payer_email = $_POST['payer_email'];
$code = $_POST['invoice'];


if (!$fp) {
// ERROR
$error = $errstr ($errno);
$db = mysql_connect($host,$user,$pass);
mysql_select_db($datab,$db);
$sql = "INSERT INTO cart_order (cart_order_id, code, txn_id, status, error) VALUES (' ','$code','$txn_id','$status','$error')";
$result = mysql_query($sql);

} else {
fputs ($fp, $header, strlen($header));
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
if ($payment_status=='Completed') { // check the payment_status is Completed
// check that txn_id has not been previously processed -this is done by unique field
if ($receiver_email=='$pp_email') { // check that receiver_email is an email address in your PayPal account
$db = mysql_connect($host,$user,$pass);
mysql_select_db($datab,$db);
$sql = "INSERT INTO cart_order (cart_order_id, code, txn_id, status) VALUES (' ','$code','$txn_id','$status')";
$result = mysql_query($sql); // process payment

}
}
$message = "$fname,\n\n$message";
$message .= "?key=$code";
// rest of vars in config file

mail("webmaster@domain.com", $subject, $message, $headers);

} elseif (strcmp ($res, "INVALID") == 0) {
$db = mysql_connect($host,$user,$pass);
mysql_select_db($datab,$db);
$sql = "INSERT INTO cart_order (cart_order_id, code, txn_id, status, error) VALUES (' ','$code','$txn_id','$res---$status','$error')";
$result = mysql_query($sql);

}
fclose ($fp);
}
}
?>

</PRE>

#6 dperry

dperry

    Newbie

  • Members
  • Pip
  • 9 posts

Posted 24 November 2002 - 04:02 PM

James,

Take a look at:

http://www.eliteweav.../ew-idh-1_4.zip

This is a Free PHP Handler by Marcus Cicero at EliteWeaver. He also has a free test environment at:

http://www.eliteweav...ing/ipntest.php

There are also other resources found at his site.

Hope this helps,

Dave



#7 Guest(old)

Guest(old)

    Junior Member

  • Members
  • 312 posts

Posted 24 November 2002 - 07:57 PM

Thanks Dave!

Well the handler script really didnt help any, but using the test script I was able to track down the flaw in my logic (hehehehehe) and a re-write got it working.

HOWEVER I now am not picking up either my invoice or custom var which I send to Paypal.

For instance my cart form that goes to pay pal shows this in source:
==============
<INPUT TYPE="hidden" NAME="custom" VALUE="1787888">
==============

Yet I get an empty post for that var on my IPN page here is my code:
==============
$code3 = $_POST['custom'];
==============

I get other vars from the post......
Sound familiar? Any Ideas?
TIA!
James

#8 dperry

dperry

    Newbie

  • Members
  • Pip
  • 9 posts

Posted 24 November 2002 - 09:32 PM

James,

I printed all the vars and their values just to see what I was getting from PayPal. I used something like this:

foreach ($HTTP_POST_VARS as $key => $value) {
echo "Key - " . $key . " Value - " . $value; ?>

Also, check your form script going to PayPal. The hidden input for single item purchase is:

<INPUT TYPE="hidden" NAME="cmd" VALUE="_xclick">

and a shopping cart purchase you will need to change to:

<INPUT TYPE="hidden" NAME="cmd" VALUE="_cart">

Hope this helps,
Dave





#9 Guest(old)

Guest(old)

    Junior Member

  • Members
  • 312 posts

Posted 24 November 2002 - 10:42 PM

<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote">Originally posted by Guest
[br]Hi,
I pretty much cut and pasted the php code, then added my MySQL bit where needed, but I am getting errors related to the fp.
line 17: $fp = fsockopen ("www.paypal.com", 80, $errno, $errstr, 30);
<hr height="1" noshade id="quote"></blockquote id="quote"></font id="quote">

Jeeze, that nearly killed my processor, lol!

fputs ($fp, $header, strlen($header)); is incorrect!
fputs ($fp, $header . $req); is what it should be!

Take of a } from the bottom an place it under:

$res = fgets ($fp, 1024);


Hope this helped?

Best regards,

Marcus Cicero
EliteWeaver UK





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users