IT.COM

CURL problem, need help quick

Spaceship Spaceship
Watch
Hello,
I made a curl which send some data to a url and the result of script should be displayed.
the script looks like this
Code:
<?php 

// Initialize curl 
$ch = curl_init(); 


// Get curl to POST 
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

// Instruct curl to suppress the output from Online Mart, and to directly  
// return the transfer instead.  (Output will be stored in $txResult.) 
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); 

// This is the location of the Online Mart payment gateway 
 

 //https://www.beanstream.com/scripts/process_transaction.asp
 curl_setopt( $ch, CURLOPT_URL, "https://www.beanstream.com/scripts/process_transaction.asp" ); 
// These are the transaction parameters that we will POST 
 $merchant_id=117489490;
 $trnCardOwner="Ashutosh";
 $trnCardNumber=4030070010001234;
 $trnExpMonth=09;
 $trnExpYear=20;
 $trnCardCVD=567;
 $trnOrderNumber=2234;
 $trnAmount=30.00;
 $ordEmailAddress="[email protected]";
 $ordName="Ashutosh";
 $ordPhoneNumber=9988736655;
 $ordAddress1="1045 Main street";
 $ordCity="Vancouver";
 $ordProvince="BC";
 $ordPostalCode="V8R1J6";
 $ordCountry="CA";
 $ash="requestType%3dT%26merchant_id%3d%22.%24merchant_id.%22%26trnCardOwner%3d%22.%24trnCardOwner.%22%26trnCardNumber%3d%22.%24trnCardNumber.%22%26trnExpMonth%3d%22.%24trnExpMonth.%22%26trnExpYear%3d%22.%24trnExpYear.%22%26trnOrderNumber%3d%22.%24trnOrderNumber.%22%26trnAmount%3d%22.%24trnAmount.%22%26ordEmailAddress%3d%22.%24ordEmailAddress.%22%26ordName%3d%22.%24ordName.%22%26ordPhoneNumber%3d%22.%24ordPhoneNumber.%22%26ordAddress1%3d%22.%24ordAddress1.%22%26ordAddress2%3d%22.%24ordAddress2.%22%26ordCity%3d%22.%24ordCity.%22%26ordProvince%3d%22.%24ordProvince.%22%26ordPostalCode%3d%22.%24ordPostalCode.%22%26ordCountry%3d%22.%24ordCountry.%22";
 /*echo curl_setopt( $ch, CURLOPT_POSTFIELDS,"requestType=BACKEND&merchant_id=117489490&trnCardOwner=Paul+Randal&trnCardNumber=4030000010001234&trnExpMonth=01&trnExpYear=05&trnOrderNumber=2232&trnAmount=10.00&[email protected]&ordName=Paul+Randal&ordPhoneNumber=9999999&ordAddress1=1045+Main+Street&ordAddress2=&ordCity=Vancouver&ordProvince=BC&ordPostalCode=V8R+1J6&ordCountry=CA&approvedPage=payment_success.php?msg=success&declinedPage=payment_success.php?msg=declined" );*/

curl_setopt( $ch, CURLOPT_POSTFIELDS,$ash); 

// Now POST the transaction.  $txResult will contain Online Mart's response 
$txResult = curl_exec($ch); 

echo "Result:<BR>"; 
echo $txResult; 
curl_close( $ch ); 


?>
It's showing the output as blank , See : http://ashutosh4u.100webspace.net/Hubcaps_canada/curl_api.php
Can some one help, need help urgently
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
not sure what the problem may be (not well versed with curl), but if that is real data (like creditcard number, name, address, etc) are you sure you want to be posting it here on a public forum?
 
0
•••
thats a fake data, just as a example
 
0
•••
It is possible that the site expects a referer, therefore it stops prematurely. Other possibility: a runtime error in your code, turn display errors on, or check the error log.
Also make sure $ash is properly urlencoded.
Finally try CURL with a non-SSL page to make sure the error is specific to that site.
 
0
•••
There may also be a redirect causing the problem. Try adding the following:

Code:
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
 
0
•••
Is curl updated on the server?
 
0
•••
0
•••
Hi,

Your setting of $ash seems to be url encoded. URL decoding it makes it look like PHP code:

Code:
$ash="requestType=T&merchant_id=".$merchant_id."&trnCardOwner=".$trnCardOwner."&trnCardNumber=".$trnCardNumber."&trnExpMonth=".$trnExpMonth."&trnExpYear=".$trnExpYear."&trnOrderNumber=".$trnOrderNumber."&trnAmount=".$trnAmount."&ordEmailAddress=".$ordEmailAddress."&ordName=".$ordName."&ordPhoneNumber=".$ordPhoneNumber."&ordAddress1=".$ordAddress1."&ordAddress2=".$ordAddress2."&ordCity=".$ordCity."&ordProvince=".$ordProvince."&ordPostalCode=".$ordPostalCode."&ordCountry=".$ordCountry."";

You probably want to urlencode each parameter like this:

Code:
$ash="requestType=T&merchant_id=".urlencode($merchant_id)."&trnCardOwner=".urlencode($trnCardOwner)."&trnCardNumber=".urlencode($trnCardNumber)."&trnExpMonth=".urlencode($trnExpMonth)."&trnExpYear=".urlencode($trnExpYear)."&trnOrderNumber=".urlencode($trnOrderNumber)."&trnAmount=".urlencode($trnAmount)."&ordEmailAddress=".urlencode($ordEmailAddress)."&ordName=".urlencode($ordName)."&ordPhoneNumber=".urlencode($ordPhoneNumber)."&ordAddress1=".urlencode($ordAddress1)."&ordAddress2=".urlencode($ordAddress2)."&ordCity=".urlencode($ordCity)."&ordProvince=".urlencode($ordProvince)."&ordPostalCode=".urlencode($ordPostalCode)."&ordCountry=".urlencode($ordCountry)."";

Try replacing the "$ash=..." line in your code with the one above.
 
0
•••
0
•••
I suspect that there is a problem with your Curl installation. Perhaps you don't have OpenSSL support compiled in. I have tried your script on one of my servers and I get a result ("Invalid merchant id (merchant_id = 0)"). Using my modification I get a different result, which looks more like what you want.

Your code does not handle errors from curl_exec. To display error messages, after:

Code:
$txResult = curl_exec($ch);

add:

Code:
if($txResult === false)
{
    echo 'Curl error '.curl_errno($ch).' : '.curl_error($ch) ;
}

Using sockets is not really a viable option since you are using an SSL connection.
 
0
•••
thank you qbert220, the problem is now found. I hope that i might not need further help. Thanks every body
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back