I am having problems installing PayPal IPN. It returns INVALID every time I process it. Is there something wrong with my code
Code:
<?php
$db_host = 'localhost';
$db_user = '';
$db_password = '';
$db_database = '';
// Connect and select database
$connect = mysql_connect($db_host, $db_user, $db_password);
$select_db = mysql_select_db($db_database);
// require_once('../includes/main.php');
// Notify command
$request = "cmd=_notify-validate";
// Prepare the URL to send via cURL
foreach ($_POST as $key => $value){
if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()){
$value = urlencode(stripslashes($value));
}else{
$value = urlencode($value);
}
$request .= "&$key=$value";
}
// Initial cURL
$ch = curl_init();
// Set opt
curl_setopt($ch,CURLOPT_URL,"https://www.sandbox.paypal.com/cgi-bin/webscr");
//curl_setopt($ch,CURLOPT_URL,"https://www.paypal.com");
curl_setopt($ch,CURLOPT_POST,true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$request);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,false);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
// Return result
$result = curl_exec($ch);
// Close cURL connection
curl_close($ch);
// If condition
if($result == 'VERIFIED'){
mysql_query("INSERT INTO paypal_ipn (verification) VALUES ('{$result}')");
}else{
mysql_query("INSERT INTO paypal_ipn (verification) VALUES ('{$result}')");
}
?>