Jump to content

Base64_encode alternative


Recommended Posts

Working on posting a module to the addons site, the validator is failing due to the use of the base64_encode() function. This function is required to encode a curl header with authentication to a payment gateway. Is there a supported alternative to this function?



Link to comment
Share on other sites



- Kindly ask your further questions in the relevant forum section.


- Try to set the headers manually:


(Example taken from php.net website)



         $credentials = "username:password"; 
         // Read the XML to send to the Web Service 
         $request_file = "./SampleRequest.xml"; 
        $fh = fopen($request_file, 'r'); 
        $xml_data = fread($fh, filesize($request_file)); 
        $url = "http://www.example.com/services/calculation"; 
        $page = "/services/calculation"; 
        $headers = array( 
            "POST ".$page." HTTP/1.0", 
            "Content-type: text/xml;charset=\"utf-8\"", 
            "Accept: text/xml", 
            "Cache-Control: no-cache", 
            "Pragma: no-cache", 
            "SOAPAction: \"run\"", 
            "Content-length: ".strlen($xml_data), 
            "Authorization: Basic " . base64_encode($credentials) 
        $ch = curl_init(); 
        curl_setopt($ch, CURLOPT_URL,$url); 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
        curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
        curl_setopt($ch, CURLOPT_USERAGENT, $defined_vars['HTTP_USER_AGENT']); 
        // Apply the XML to our curl call 
        curl_setopt($ch, CURLOPT_POST, 1); 
        curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data); 

        $data = curl_exec($ch); 

        if (curl_errno($ch)) { 
            print "Error: " . curl_error($ch); 
        } else { 
            // Show me the result 
Link to comment
Share on other sites

You should continue using the function and tell the addons team that this is required functionality for your external vendor connectivity.  They may complain a bit, but there is nothing wrong with using base64 encode and decode, there are absolutely no security issues with it in the manner you are using it.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...