Current location: Hot Scripts Forums » Programming Languages » PHP » php decode 64 xml


php decode 64 xml

Reply
  #1 (permalink)  
Old 07-06-08, 03:49 PM
naf naf is offline
New Member
 
Join Date: Jul 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
php decode 64 xml

hi..

just joined . hi to everyone.

I am trying to setup a xml for a friend of mine.. the source is a remote http server ...and you can send differnt api request to it and you recieve a responce depending on the request.

In the api documentation it says the userid and login id must be base 64 encoded..The api request query i send to the remote server I encode the userid and login id.

I am trying to echo the responce and all get is encoded message.I am been trying to figure out what i need to do to decode it.i tried echo base64_decode($str); but all i get is blank page ..if i do just echo $responce then i get a responce but is un readable.

here is the code ii am trying to use.i am usng php 5
PHP Code:

<?php
$service_url 
"https://remote.server.com"?>
<?php
$xml 
'<apiRequest xmlns="API_Request_ProductDetails"> <header> <apiVersion>1</apiVersion> <userID>base64 encoded</userID> <loginGUID>base64 encoded</loginGUID> </header> <request> <searchRequest> <itemcode>item no1</itemcode> </searchRequest> </request> </apiRequest>';?> 


<?php
// set curl header options
$curl_header "POST “.$service_url.” HTTP/1.0 \r\n";
$curl_header .= "MIME-Version: 1.0 \r\n";
$curl_header .= "Content-type: application/PTI26 \r\n";
$curl_header .= "Content-length: ".strlen($xml)." \r\n";
$curl_header .= "Content-transfer-encoding: text \r\n";
$curl_header .= "Request-number: 1 \r\n";
$curl_header .= "Document-type: Request \r\n";
$curl_header .= "Interface-Version: Test 1.4 \r\n";
$curl_header .= "Connection: close \r\n\r\n";
$curl_header .= $xml;// add xml to header
$curl curl_init();// create curl handler
// set curl options
curl_setopt($curlCURLOPT_URL$service_url);
curl_setopt($curlCURLOPT_RETURNTRANSFER1);
curl_setopt($curlCURLOPT_TIMEOUT30);
curl_setopt($curlCURLOPT_CUSTOMREQUEST$curl_header);
curl_setopt($curlCURLOPT_SSL_VERIFYPEER0);
curl_setopt($curlCURLOPT_SSL_VERIFYHOST0);
$response curl_exec($curl);// execute the curl request
if(curl_errno($curl)){// check for error in processing curl request
exit;
}
curl_close($curl);// close the curl connection    
?>
   
<?php 
  

//process the returned ****ty xml  
echo $response;

//print $response;
//$str = $response;
//echo base64_decode($str);

?>

the responce i get from remote server when i do view source is

xml Code:
  1. </element>
  2.   </attributes>
  3.   <specification>
  4.     <spec_element>
  5.       <spec_title>S2V5Ym9hcmQ=</spec_title>
  6.       <spec_description>TnVtYmVyIG9mIEtleXM=</spec_description>
  7.       <spec_value></spec_value>
  8.     </spec_element>
  9.  
  10.     <spec_element>
  11.       <spec_title>S2V5Ym9hcmQ=</spec_title>
  12.       <spec_description>TnVtYmVyIG9mIEhvdGtleXM=</spec_description>
  13.       <spec_value></spec_value>
  14.     </spec_element>
  15.     <spec_element>
  16.       <spec_title>S2V5Ym9hcmQ=</spec_title>
  17.  
  18.       <spec_description>SW50ZXJuZXQgS2V5</spec_description>
  19.       <spec_value></spec_value>
  20.     </spec_element>
  21.     <spec_element>
  22.       <spec_title>S2V5Ym9hcmQ=</spec_title>
  23.       <spec_description>U2NyZWVuIExvY2sgS2V5</spec_description>

How do i call the decode function ?

Last edited by Nico; 07-06-08 at 05:09 PM. Reason: Wrappers.
Reply With Quote
  #2 (permalink)  
Old 07-07-08, 01:14 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
the problem is that your trying to decode the whole xml file even though only the contents is encoded.
PHP Code:

echo base64_decode('S2V5Ym9hcmQ='); // outputs 'keyboard' which seems correct 

To get around this you need to parse the xml file and decode only the content of your elements. To ease the parsing process php offers two built in classes (atleast in php5), SimpleXML and XMLParser.
SimpleXML is indeed easy and looping trough the object it creates is pretty simple. Hope that helps you some.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Embeding PHP code in XML?? ausgezeichnete PHP 7 01-28-08 05:38 AM
2 profitable script sites for sale cms-master.com General Advertisements 3 07-03-07 10:17 AM
PHP And XML Parse Chris English PHP 4 07-11-06 04:14 PM
PHP, XML images. nightlord PHP 1 07-05-06 09:09 PM
php and xml pdaniel2004 PHP 0 11-01-04 08:02 AM


All times are GMT -5. The time now is 07:49 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.