<?php
    header
("Content-type: text/html; charset=utf-8");   
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>Web service client - setting up a SOAP header</title>
        <meta name="language" content="en" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <meta http-equiv="Cache-Control" content="no cache" />
        <meta http-equiv="Pragma" content="no_cache" />
        <meta name="author" content="attila szabo (www.w3net.eu)" />
        <meta name="robots" content="noindex, nofollow" />
        <style type="text/css">
        body {
            font-family: verdana;
            background: #ffffff; 
        }
        .xmlBox {
            width: 80%;
            border:1px solid #B2B2B2;
            height: 140px;
            background:#F4F4F4 none repeat scroll 0 0;
            word-spacing:normal;
            padding: 4px;
        }
        .message {
            margin: 1.5em 0;
            padding: 15px;
            font-size: 90%;
            line-height: 1.5em;
            border-left: none;
            border-right: none;
        }
        .error {
            background-color: #FFDDCC;
            border-top: 3px solid #DD0000;
            border-bottom: 3px solid #DD0000;
        }
        .success {
            background-color: #A2D489;
            border-top: 3px solid #339900;
            border-bottom: 3px solid #339900;
        }
        </style>
    </head>
<body>
<pre>
<?php
    error_reporting
(E_ALL);
    
$xmlns 'urn:ExampleAPI';
    
$sig '0c9ed93ec403851a2f7682aceb98a5a9';


    try{

        
$client = new SoapClient('http://w3net.eu/code/soap/soap_header/server/service.wsdl', array(
                                 
'style'    => SOAP_DOCUMENT,
                                 
'use'      => SOAP_LITERAL,
                                 
'encoding' => 'UTF-8',
                                 
'trace'    => 1
                                
));


        
// SOAP Header beállítása
        
class ApiUserAuthHeader {
            function 
__construct($sid){
                 
$this->sessionId = new SoapVar($sid,XSD_STRING,NULL,NULL,'sessionId','urn:ExampleAPI');
            }
        }

        
$auth = new ApiUserAuthHeader('ce50f06c3f00a938ddeb78b22bb33c7192932006');

        
/* You MUST encode the object */
        
$authVar = new SoapVar($authSOAP_ENC_OBJECT);
        
$header =  new SoapHeader('urn:ExampleAPI'"ApiUserAuthHeader",$authVarFALSESOAP_ACTOR_NEXT);
        
$client->__setSoapHeaders(array($header));


        
$params = array('apiKey' => 'WorkaholicGroupApiKey',
                        
'sig'    => $sig);
        
$ret $client->login($params);
        echo 
var_dump($ret);

    } catch (
SoapFault $exception) {

        if (
stristr($exception->faultstring,'Couldn\'t load from')){
            die(
"Error: Your computer must be connected to the Internet. Connect to the Internet and try again.");
        }else{
            echo 
'Last Request Headers';
            echo 
"\n<div class='xmlBox'>"htmlspecialchars($client->__getLastRequestHeaders()) ."</div>\n";
            echo 
'Last Request';
            echo 
"\n<textarea class='xmlBox'>"htmlspecialchars($client->__getLastRequest()) ."</textarea>";
            echo 
"\n<div class='msg error'>SOAP client Error: "$exception->faultstring ."</div>\n\n";
        }

    }
?></pre>
<a href="index.php?no_cache=<?php echo time();?>">refresh page</a>
</body></html>