Location: PHPKode > scripts > PHP Hosting Directory > phphost_directoryv2/ipn/paypal.php
<?

include ("../config.inc.php");

$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'];
$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'];

$order_id         = $_POST['item_number'];

if (!$fp)
{
  $msg .= "HTTP ERROR\r\n";
}
else
{
  fputs ($fp, $header . $req);
  while (!feof($fp))
  {
    $res = fgets ($fp, 1024);
    if (strcmp($res, "VERIFIED") == 0)
    {
      if ($payment_status == 'Completed')
      {
        $status = mysql_result(mysql_query("SELECT `status` FROM `hsl_order` WHERE `order_id`='$order_id'"), 0, 0);
        if ($status != 'Finished')
        {
          mysql_query("UPDATE `hsl_order` SET `status`='Finished', `description`='This transaction has been approved' WHERE `order_id`='$order_id'");
          $order = mysql_fetch_assoc(mysql_query("SELECT *, h.`account_type` AS curr_acount_type, IF(h.`expired`<NOW(), 1, 0) AS expired_flag FROM `hsl_order` o LEFT JOIN `hsl_price` p ON o.`price_id`=p.`price_id` LEFT JOIN `hsl_host` h ON o.`username`=h.`username` WHERE o.`order_id`='$order_id'"));
          if ($order['account_type'] == $order['curr_acount_type'])
          {
            $msg .= "\r\n1\r\n";
            if ($order['expired_flag'] == 0)
            {
              $sql = "UPDATE `hsl_host` SET `expired`=FROM_DAYS(TO_DAYS(`expired`)+".($order['period']*30).") WHERE `username`='".$order['username']."'";
            }
            else
            {
              $sql = "UPDATE `hsl_host` SET `expired`=FROM_DAYS(TO_DAYS(NOW())+".($order['period']*30).") WHERE `username`='".$order['username']."'";
            }
          }
          else
          {
            $msg .= "\r\n2\r\n";
            $sql = "UPDATE `hsl_host` SET `account_type`='".$order['account_type']."', `expired`=FROM_DAYS(TO_DAYS(NOW())+".($order['period']*30).") WHERE `username`='".$order['username']."'";
          }
          mysql_query($sql);
        }
      }
      else
      {
        $msg .= "\r\n3\r\n";
        mysql_query("UPDATE `hsl_order` SET `status`='".$payment_status."', `description`='' WHERE `order_id`='$order_id'");
      }
    }
  }
  fclose ($fp);
}

?>
Return current item: PHP Hosting Directory