Jump to content

__setCookie not working in SOAP request


davyb

Recommended Posts

Hi guys,

Im trying to work with a wsdl which allows me to login and sends back a token (cookie) in the response. Whenever I strip out the token and the use __setCookie to set the cookie for future requests all other requests will not authenticate... Anyone any ideas please? Im really at a loose end...

 

Heres the code Im using...

 

<?php

ini_set("soap.wsdl_cache_enabled", "0");

$url = "some.wsdl";
//$url = "http://ws.some.com/services/some?wsdl";

$soap = new SoapClient($url, array('trace' => true));


// try 3 times to login
for($i = 0; $i < 3; $i++){

try{

	$result = $soap->opLogin(array('name' => 'username', 'cleartext' => 'password'));

	$token = $result->info;

	$token = trim(str_replace("PubAuth1=", "", $token));

	// Print token
	echo "token - cookie:";
	print($token);
	echo "<br>";

	// Set cookie
	//$soap->__setCookie('PubAuth1', $token);
	createSession();

	// Retry loopje
	for($i = 0; $i < 3; $i++){
		try{

			// This is the second call which will not authenticate....
			$result2 = $soap->__soapCall("opSetUser", array("email" => "me@you.com", 'p' =>'password123'));

			// Print result

			echo "opSetUser result: ";
			var_dump($result2);
			exit;
		}
		catch(Exception $ex){
			echo "opSetUser error: " . $ex->getMessage() . "<br>";
		}
	}

}
catch(Exception $ex) {
	echo "opLogin error: " . $ex->getMessage() . "<br>";
}

}
?>

 

THanks in advance.

 

Davy

Link to comment
Share on other sites

Apologies,

this is my code (few typos in the last one...) :P

 

<?php

function createSession() {
        global $soap;

        $responseHeader = $soap->__getLastResponseHeaders();

var_dump($responseHeader);

        $sessionPos=strpos($responseHeader, "PubAuth1=");

        if ($sessionPos === false) {
            echo "No session id was found. Exiting.\n";
            exit();
        }
        //cookie will always be 32 bytes
        $cookie = substr($responseHeader,$sessionPos + 11,32);

        #
        # Set the Cookie name for the next request
        $soap->__setCookie("PubAuth1", $cookie);
    }


ini_set("soap.wsdl_cache_enabled", "0");

$url = "some.wsdl";


$soap = new SoapClient($url, array('trace' => true));

for($i = 0; $i < 3; $i++){

try{

	$result = $soap->opLogin(array('name' => 'Username', 'cleartext' => 'password'));


	$token = $result->info;

	$token = trim(str_replace("PubAuth1=", "", $token));


	// Set cookie
	createSession();

	// Retry loopje
	for($i = 0; $i < 3; $i++){
		try{

			$result2 = $soap->__soapCall("opSetUser", array("email" => "me@me.com", 'p' =>'password123'));


		}
		catch(Exception $ex){
			echo "opSetUser error: " . $ex->getMessage() . "<br>";

		}
	}

}
catch(Exception $ex) {
	echo "opLogin error: " . $ex->getMessage() . "<br>";
}

}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.