Help with PP IPN Script - it quit working - give me your quotes please

9 replies
Hi all,

I am very frustrated at the moment and need help with my IPN script.
It used to work without any problems but now doesn't seem to work the way it should any more.

Orders are going through without any problems but the script doesn't send emails anymore and does not post the entries into my database. Here is the script if you have any idea on how to solve this let me know I'm willing to pay for this.

Script:

Code:
<?php

	$datHost = "localhost";
	$datName = "*****";
	$datUser = "*****";
	$datPass = "*****";

	$datBase = mysql_connect($datHost, $datUser, $datPass);

	mysql_select_db($datName, $datBase);

//------------------------------------------------
// Read post from PayPal system and create reply
// starting with: 'cmd=_notify-validate'...
// then repeating all values sent - VALIDATION.
//------------------------------------------------


$postvars 	= array();
while (list ($key, $value) = each ($HTTP_POST_VARS))
	{
		$postvars[] = $key;
	}
$req 		= 'cmd=_notify-validate';

for ($var = 0; $var < count ($postvars); $var++)
	{
		$postvar_key 		= $postvars[$var];
		$postvar_value 		= $$postvars[$var];
		$req 			.= "&" . $postvar_key . "=" . urlencode ($postvar_value);
	}
//--------------------------------------------
// Create message to post back to PayPal...
// Open a socket to the PayPal server...
//--------------------------------------------
$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 ("www.paypal.com", 80, $errno, $errstr, 30);


//----------------------------------------------------------------------
// Check HTTP connection made to PayPal OK, If not, print an error msg
//----------------------------------------------------------------------
if (!$fp)
	{
		$res = "FAILED";
	}
else
	{
		fputs ($fp, $header . $req);

		while (!feof($fp))
			{
				$res = fgets ($fp, 1024);
				
				if (strcmp ($res, "VERIFIED") == 0)
					{
						if (strcmp($tpayment_status, "Refunded") == 0)
							{
								$parent_txn_id	= "REFUNDED|".$parent_txn_id;
								$sql			= "UPDATE pp_Payments SET payment_id = '$parent_txn_id' WHERE payer_email = '$payer_email'";
										
								mysql_query($sql,$datBase);
							}	

						if (strcmp($tpayment_status, "Reversed") == 0)
							{
								$parent_txn_id	= "REVERSED|".$parent_txn_id;
								$sql			= "UPDATE pp_Payments SET payment_id = '$parent_txn_id' WHERE payer_email = '$payer_email'";
										
								mysql_query($sql,$datBase);
							}	
														
						if (strcmp ($payment_status, "Completed") == 0 || strcmp($txn_type, "subscr_signup") == 0 || strcmp($txn_type, "subscr_cancel") == 0)
							{
								if (strcmp($txn_type, "subscr_payment") != 0 && strcmp($txn_type, "subscr_cancel") != 0)
									{
										$strIPaddress	= $_SERVER['REMOTE_ADDR'];
										$fecha 			= strtotime($payment_date);
										$Date 			= date('Y-m-d',$fecha);

										if(strcmp($txn_type, "subscr_signup") == 0)
											{
												$txn_id		= $subscr_id;
												$mc_gross	= '0.00';	
												$mc_fee		= '0.00';
											}	

												$sql = "INSERT into pp_Payments
													(
														item_name,
														item_number,
														mc_gross,
														mc_fee,
														first_name,
														last_name,
														payer_email,
														payment_date,
														payment_id,
														ip_address,
														AFF_ID
													)

													VALUES
													(
														'$item_name',
														'$item_number',
														'$mc_gross',
														'$mc_fee',
														'$first_name',
														'$last_name',
														'$payer_email',
														'$Date',
														'$txn_id',
														'$strIPaddress',
														'$custom'
													) ";

											mysql_query($sql,$datBase);
																							
											$strSubject = "Discover The Divine Truth eBook";
											$strBody   .= "Dear ".$first_name." ".$last_name.",\n\n";
											$strBody   .= "Thank you for your purchase of Discover The Divine Truth eBook! You may download the ebook including the bonus from the link below:\n\n";
											$strBody   .= "http://www.discoverthedivinetruth.com/DownLoad.php?KEYS=".$txn_id."\n\n";											
											$strBody   .= "All the Best,\n\n";
											$strBody   .= "Tino Hartung";

											mail($payer_email, $strSubject, $strBody, "From: webhomez@web.de", "-fwebhomez@web.de");
									}
									
								 if (strcmp($txn_type, "subscr_cancel") == 0)
									{
										$subscr_id = "CANCELLED|".$subscr_id;
										$sql = "UPDATE pp_Payments SET payment_id = '$subscr_id' WHERE payer_email = '$payer_email'";
										
										mysql_query($sql,$datBase);
									}	
							}

					}
			}
	}

//-------------------------------------------
// Close PayPal Connection, Log File and DB.
//-------------------------------------------

	fclose ($fp);
	mysql_close($db);

?>
The only thing coming in my mind is that there was an server update the last 2 months and some scripts on my sitesquit working because POST variables are now only allowed to be used in this format: $_POST[variable]

I'm not sure if that is the problem, however it could be. My problem though is which variables to change that it will work again???

Please let me know if you have the solution and if you need money and more data to solve this let me know how much and what you need.

Thanks a lot

Tino
#give #ipn #quit #quotes #script #working
  • Profile picture of the author Spencer Westwood
    Try changing $HTTP_POST VARS to $_POST on line 20.

    i.e instead of

    while (list ($key, $value) = each ($HTTP_POST_VARS))

    while (list ($key, $value) = each ($_POST))


    Kind regards, Spencer
    {{ DiscussionBoard.errors[231598].message }}
  • Profile picture of the author DonTino
    nope that didn't do it thanks anyway spencer

    Any other ideas?

    Tino
    {{ DiscussionBoard.errors[231826].message }}
    • Profile picture of the author Spencer Westwood
      Calling the ipn directly I get,

      Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in /home/divinity/public_html/ipn.php on line 148

      So I guess you need to comment that line out. It's not entirely necessary..

      "

      mysql_close() closes the non-persistent connection to the MySQL server that's associated with the specified link identifier. If link_identifier isn't specified, the last opened link is used.
      Using mysql_close() isn't usually necessary, as non-persistent open links are automatically closed at the end of the script's execution. See also freeing resources."


      Kind regards, Spencer
      {{ DiscussionBoard.errors[232401].message }}
  • Profile picture of the author rwil02
    Saw this info and it might help you

    Migrating from PHP4 to PHP5 : php5, php4, from, migrating

    If you are not using any OOP techniques, then upgrade to the latest PHP V4.

    The next big issue for PHP is going to be in PHP6. This is removing a LOT of the hand holding that is available in PHP4 and to an extent in PHP5.

    For a lot of users, $HTTP_xxxx_VARS are used. Not in PHP6.

    register_globals gone, so if you have a form with a <input type="text" name="my_username">, you will no longer have $my_username automatically populated. Instead, you would need to use $_GET['my_username'] (if the form's method was "GET"), $_POST['my_username'] (for "POST"), or you could use $_REQUEST['my_username'] if you don't care/know where the data comes from.

    magic_quotes - no longer used - it is up to you to deal with the data, not for PHP to make a best guess and screw it up!

    But in truth, these are relatively minor things and have been talked about for a LONG time. The best practise is to do all the things that would in effect make the removal of these "facilities" unnoticed. If you don't use register_globals, you won't know it is gone!


    Why not get a standalone PC, install PHP5 and test the site. Maybe open it as a beta.site.com rather than a www.site.com?

    You MAY get no errors! In which case the PHP4 code is clean and well written.

    At the moment, there is no _easy_ way to run both PHP4 and PHP5 on the same machine.
    Signature

    Roger Willcocks
    L-Space Design
    Please vote to help me win a 3kW solar array

    {{ DiscussionBoard.errors[233230].message }}
  • Profile picture of the author DonTino
    Hi Roger thanks a lot for the info but I doubt it will help me my Site is running PHP4.4.7

    Spencer thanks also but that didn't do the trick neither.

    Tino
    {{ DiscussionBoard.errors[233368].message }}
  • Profile picture of the author rwil02
    Ok.
    If you know what the version was before the upgrade, you should be able to find a list of what defaults have been changed.

    Getting those set back would probably solve the problem.
    Signature

    Roger Willcocks
    L-Space Design
    Please vote to help me win a 3kW solar array

    {{ DiscussionBoard.errors[235202].message }}
  • Profile picture of the author Emilian
    I am a PayPal Certified Developer so if you have not been able to find the fix for this I can definitely take a look at it for you so that it works again Sending you a PM.
    {{ DiscussionBoard.errors[236747].message }}
  • Profile picture of the author DonTino
    Thanks a lot all I have a few offers now to look over it. I'm checking them out onr after th other until it works.

    Tino
    {{ DiscussionBoard.errors[238140].message }}
  • Profile picture of the author DonTino
    Spencer was able to fix this for me so no need for any further help.

    Thanks a lot,

    Tino
    {{ DiscussionBoard.errors[240893].message }}

Trending Topics