Response:
----------

<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns3:createsessionResponse xmlns="http://www.utiba.com/delirium/ws/TypedQuery" xmlns:ns2="http://www.utiba.com/delirium/ws/Misc" xmlns:ns3="urn:UMARKETSCWS" xmlns:ns4="http://www.utiba.com/delirium/ws/StdQuery">
<ns3:createsessionReturn>
<ns3:sessionid>6DL42ED0GG67MADDTD96</ns3:sessionid>
<ns3:result>0</ns3:result>
<ns3:result_namespace>session</ns3:result_namespace> <ns3:createsessionReturn> <ns3:createsessionResponse> <S:Body> <S:Envelope>

-------------------------

How can i get xmlns Attribute Values using PHP. <ns3:sessionid>6DL42ED0GG67MADDTD96</ns3:sessionid> I want to take <ns3:sessionid> value [6DL42ED0GG67MADDTD96] .

Please reply asap. very urgent.

Thanks
William

$path = 'response.xml'; // this is your response saved to file
  $doc = simplexml_load_file($path);
  $doc->registerXPathNamespace('ns3', 'urn:UMARKETSCWS');
  $nodelist = $doc->xpath('//ns3:createsessionResponse/ns3:createsessionReturn/ns3:sessionid');
  echo 'Session ID: ' . (string)$nodelist[0];

Hi thanks for your grate help . I have another problem to read string. I just give my sample code..below..

----------------------------------
redeem.php
------------

<?php

// assing request values as string to $content varaiable.

 $content = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org /soap/envelope/" xmlns:urn="urn:UMARKETSCWS">
				   <soapenv:Header/>
				   <soapenv:Body>
					  <urn:createsession/>
				   </soapenv:Body>
				</soapenv:Envelope>';

// Assign headers
$headers = array("Content-type: text/xml;charset=\"utf-8\"", 
				 "Accept: application/soap+xml, text/*", 
				 "Cache-Control: no-cache", 
				 "Pragma: no-cache", 
			     "SOAPAction: urn:UMARKETSCWS/createsession", 
				 "Content-length: ".strlen($content),
				); 

// URL 
$wsdl  = "https://202.152.162.213:8443/services/umarketsc?wsdl";

//CURL here

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $wsdl); // pass wsdl url here
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_VERBOSE, '1');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $content); // pass content variable here
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, '1');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // pass headers variable here
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, '1');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

// Execute curl here
$resp = curl_exec($ch);

$res = htmlspecialchars($resp, ENT_QUOTES);
$res=str_replace('&gt;&lt;/','&gt; &lt;',$res);
$res=str_replace('&gt;&lt;','&gt;<BR>&lt;',$res);

// print output here

print_r('<pre>');
print_r($res);
print_r('</pre>');

?>

------------------ end code-----------------

OUTPUT in webpage here:
------------

HTTP/1.1 200 OK
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Set-Cookie: JSESSIONID=1fxif6gw8x33k;Path=/
Content-Type: text/xml; charset=utf-8
Transfer-Encoding: chunked
Server: Jetty(6.1.6)

<?xml version="1.0" ?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns3:createsessionResponse xmlns="http://www.utiba.com/delirium/ws/TypedQuery" xmlns:ns2="http://www.utiba.com/delirium/ws/Misc" xmlns:ns3="urn:UMARKETSCWS" xmlns:ns4="http://www.utiba.com/delirium/ws/StdQuery">
<ns3:createsessionReturn>
<ns3:sessionid>073XM2OAFR6UOI15N2LA</ns3:sessionid>
<ns3:result>0</ns3:result>
<ns3:result_namespace>session</ns3:result_namespace> <ns3:createsessionReturn> <ns3:createsessionResponse> <S:Body> <S:Envelope>

--------------------------

I want to remove the headers in the output. I just want to read as xml string from $resp variable using simplexml_load_string function. Please give reply asap.

Or how can save as xml file from $resp variable.

Thanks

William

Use:

curl_setopt($ch, CURLOPT_HEADER, false);

Hi,

Thanks for your help friend. I got it what i want..


cheers
William

Please mark this thread as solved then.

Hi, I have another problem. I will put my code below.

-------------- reedem.php ------------

<?php
 			session_start();
			
		      $content = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:UMARKETSCWS">
				   <soapenv:Header/>
				   <soapenv:Body>
					  <urn:createsession/>
				   </soapenv:Body>
				</soapenv:Envelope>';
		
			$wsdl  = "https://202.152.162.213:8443/services/umarketsc?wsdl";

		$headers = array("Content-type: text/xml;charset=\"utf-8\"", 
				 "Accept: application/soap+xml, text/*", 
				 "Cache-Control: no-cache", 
				 "Pragma: no-cache", 
			     "SOAPAction: urn:UMARKETSCWS/createsession", 
				 "Content-length: ".strlen($content),
				); 
			$ch = curl_init(); 
			curl_setopt($ch, CURLOPT_URL, $wsdl); 
			curl_setopt($ch, CURLOPT_HEADER, false); 
			curl_setopt($ch, CURLOPT_VERBOSE, '1');
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
			curl_setopt($ch, CURLOPT_POSTFIELDS, $content); 
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, '1');
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, '1');
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
			curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
			$resp = curl_exec($ch);
			$doc = simplexml_load_string($resp);
			$doc->registerXPathNamespace('ns3', 'urn:UMARKETSCWS');
			$nodelist = $doc->xpath('//ns3:createsessionResponse/ns3:createsessionReturn/ns3:sessionid');
			echo 'Session ID: ' . (string)$nodelist[0].'<br><br>';
			$sessionid = (string)$nodelist[0];
			
			[B]$_SESSION['umarketsession'] = $sessionid;[/B]
			if(curl_errno($ch))
			{
				echo 'Error no : '.curl_errno($ch).' Curl error: ' . curl_error($ch);
			}
			// close cURL resource, and free up system resources
			curl_close($ch);
				

 ?>
 
 
 <a href="redeemlogin.php"><b>Login</b></a>

------------------ redeem code end------------------------------------------

-----------redeemlogin.php---------------------------------------------------

<?php
 			session_start();
		 		
		// Login Part Starts here
		
			$username = 'webonline';
			$password = '123456';
			[B]$sessionid = $_SESSION['umarketsession'];[/B]

			$res = strtolower($username).$password;
			$res = strtolower(sha1_exec($res));
			$res = $sessionid.$res;
			$new_pin = strtoupper(sha1_exec($res));
			
			function sha1_exec($source)
			{
			  return base64_encode(hex2bin(sha1($source)));
			}
			
			function hex2bin($hexSource)
			{
				for ($i=0;$i<strlen($hexSource);$i=$i+2)
				{
				  $bin .= chr(hexdec(substr($hexSource,$i,2)));
				}
			  return $bin;
			}

				   $content = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:UMARKETSCWS" xmlns:std="http://www.utiba.com/delirium/ws/StdQuery" xmlns:misc="http://www.utiba.com/delirium/ws/Misc">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:login>
      [B]   <urn:loginRequest><urn:sessionid>'.$sessionid.'</urn:sessionid><urn:initiator>webonline</urn:initiator><urn:pin>'.$new_pin.'</urn:pin>
		 </urn:loginRequest>[/B]
      </urn:login>
   </soapenv:Body>
</soapenv:Envelope>';

echo $content.'<br>';
		
			$wsdl  = "https://202.152.162.213:8443/services/umarketsc?wsdl";

		$headers = array("Content-type: text/xml;charset=\"utf-8\"", 
				 "Accept: application/soap+xml, text/*", 
				 "Cache-Control: no-cache", 
				 "Pragma: no-cache", 
			     "SOAPAction: urn:UMARKETSCWS/login", 
				 "Content-length: ".strlen($content),
				); 
			$ch = curl_init(); 
			curl_setopt($ch, CURLOPT_URL, $wsdl); 
			curl_setopt($ch, CURLOPT_HEADER, false); 
			curl_setopt($ch, CURLOPT_VERBOSE, '1');
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
			curl_setopt($ch, CURLOPT_POSTFIELDS, $content); 
			curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, '1');
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, '1');
			curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
			curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
			$resp = curl_exec($ch);
			$doc = simplexml_load_string($resp);
			$doc->registerXPathNamespace('ns3', 'urn:UMARKETSCWS');
			$nodelist = $doc->xpath('//ns3:loginResponse /ns3:loginReturn/ns3:result');
			echo 'Result : ' . (string)$nodelist[0].'<br><br>';
			if(curl_errno($ch))
			{
				echo 'Error no : '.curl_errno($ch).' Curl error: ' . curl_error($ch);
			}
			// close cURL resource, and free up system resources
			curl_close($ch);
			
 ?>
 
 
 <a href="redeem.php"><b>Go back</b></a>

--------------------------------------- redeemlogin.php end ----------------------

Problem:

1. redeem.php which used for createsession.
2. redeemlogin.php which is used for login our client server (wsdl url).

Can we send request to WSDL URL in same page instead of using two page(redeem and redeem login). The redeem.php page which is return sessionid from WSDL url. And i will assing one session which is called $_SESSION. Then i get this sessionid and used in redeemlogin.php page for login. Becuase I need send three parameters in redeemlogin.php(sessionid, initiator,pin).

Both(redeem.php and redeemlogin.php) xml request is different. thats why i am using different page. I hope you will understand. please give me reply asap.

Thanks
William

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.