<?php
ob_start();
session_start();
if($_SESSION['lang']=='')
{
	$_SESSION['lang'] = "en";
}

include 'languages/lang_common_'.$_SESSION['lang'].'.php';
include("include/db.inc.php");
include("include/bit_functions.inc.php");
include("include/mail.php");
$db1=new db;
$db1->open();

// 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 ('www.paypal.com', 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'];
$amount = $_POST['amount'];
$currency_code = $_POST['currency_code'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];
$date=date("Y-m-d");
if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
  if($payment_status=='Completed')
  {
  $sql="insert into t123go_transactions values ('','$item_number','$item_name','$payment_status','$amount','$currency_code','$txn_id',$receiver_email','$payer_email')";
	$q=@mysql_query($sql);

	$sql="update into t123go_memberpack set payment='c' where id='$item_number'";
	$q=@mysql_query($sql);
  }
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
?>