roldahayes Posted June 25, 2014 Share Posted June 25, 2014 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...? Quote Link to comment Share on other sites More sharing options...
roldahayes Posted June 25, 2014 Author Share Posted June 25, 2014 * 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" ); Quote Link to comment Share on other sites More sharing options...
Solution requinix Posted June 25, 2014 Solution Share Posted June 25, 2014 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); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.