Jump to content

using fsockopen function with EPDQ


Go to solution Solved by requinix,

Recommended Posts

Hi,

After a few years of having Barclays EPDQ payment gateway, they have now changed how they require the data to be sent to them - This has caused my site to stop working.

 

Now when the page redirects to epdq it is saying that the "Encrypted data is not present"

 

The original code for the fsockopen function was:

 

 

$fp = fsockopen('ssl://secure2.epdq.co.uk'. $host, 443, &$errno, &$errstr, 60);
 
if(!$fp) { print "$errstr ($errno)<br />\n"; } else {
fputs($fp, "POST /cgi-bin/CcxBarclaysEpdqEncTool.e HTTP/1.0\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\n");
fputs($fp, "Content-length: ".strlen($params)."\n\n");
fputs($fp, $params."\n\n");
while(!feof($fp)) { $output .= fgets($fp, 1024); }
fclose($fp);
}
 
$response_lines = explode("\n",$output);
$response_line_count = count($response_lines);
for($i=0; $i<$response_line_count; $i++){
if(preg_match("/epdqdata/",$response_lines[$i])) {
$curlencrypt = $response_lines[$i];
}
}

 

 

They have suggested this code instead:

 

 

$header = "POST /cgi-bin/CcxBarclaysEpdqEncTool.e HTTP/1.1\n";
$header .= "Host: secure2.epdq.co.uk\n";
$header .= "Connection: close\n";
$header .= "Content-Type: application/x-www-form-urlencoded\n";
$header .= "Content-Length: " . strlen($data) . "\n\n";
$fp = @fsockopen("ssl://secure2.epdq.co.uk", 443, $errno, $errstr, 30);

 

and then suggested using this to align it with the way my page is coded:

 

 

fputs( $fp, "Content-type: application/x-www-form-urlencoded\n" );
fputs( $fp, "Content-length: ".$strlength."\n\n" );
fputs( $fp, "Host: ".$host."\n\n" );
fputs( $fp, $postdata."\n\n" );

 

Can anyone point me in the right direction with this...?

 

Link to comment
https://forums.phpfreaks.com/topic/289281-using-fsockopen-function-with-epdq/
Share on other sites

* UPDATE

 

Epdq have now sent this:

 

 

"The key is to include both “Host” and “Connection” headers with the POST request.  The following is a modified version of part of the ‘fsockopen’ sample code supplied in the legacy ePDQ CPI Integration Guide:"

 

#write the data to the encryption cgi

$strlength = strlen($postdata);

fputs( $fp, "POST $usepath HTTP/1.0\r\n");

fputs( $fp, "Host: ".$host."\r\n");

fputs( $fp, "Content-type: application/x-www-form-urlencoded\r\n" );

fputs( $fp, "Content-length: ".$strlength."\r\n" );

fputs( $fp, "Connection: close\r\n\r\n");

fputs( $fp, $postdata."\r\n" );

  • Solution

The two things they pointed out are important. Very important.

 

But really, you shouldn't be doing this HTTP stuff yourself. Use cURL. Looks like

$curl = curl_init("https://secure2.epdq.co.uk/cgi-bin/CcxBarclaysEpdqEncTool.e");
curl_setopt_array($curl, array(
	CURLOPT_POST => true,
	CURLOPT_POSTFIELDS => $params,
	CURLOPT_RETURNTRANSFER => true
));
$output = curl_exec($curl);
curl_close($curl);
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.